Skip to content

Commit 464e329

Browse files
committed
First commit - add the functions that makes the package work :)
1 parent b0f10db commit 464e329

File tree

12 files changed

+569
-2
lines changed

12 files changed

+569
-2
lines changed

.coveragerc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[run]
2+
omit = */migrations/*,venv/*
3+
4+
[coverage:report]
5+
skip_empty = true
6+
omit = */migrations/*,*/test*,*/tests/,venv/*
7+

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
max-line-length = 120
3+
exclude = migrations/*,venv/*
4+
max-complexity = 10

.gitignore

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
2+
# Created by https://www.toptal.com/developers/gitignore/api/python,pycharm,code,sublime
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=python,pycharm,code,sublime
4+
5+
### Code ###
6+
.vscode/*
7+
!.vscode/settings.json
8+
!.vscode/tasks.json
9+
!.vscode/launch.json
10+
!.vscode/extensions.json
11+
*.code-workspace
12+
13+
### PyCharm ###
14+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
15+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
16+
17+
# User-specific stuff
18+
.idea/**/workspace.xml
19+
.idea/**/tasks.xml
20+
.idea/**/usage.statistics.xml
21+
.idea/**/dictionaries
22+
.idea/**/shelf
23+
24+
# Generated files
25+
.idea/**/contentModel.xml
26+
27+
# Sensitive or high-churn files
28+
.idea/**/dataSources/
29+
.idea/**/dataSources.ids
30+
.idea/**/dataSources.local.xml
31+
.idea/**/sqlDataSources.xml
32+
.idea/**/dynamic.xml
33+
.idea/**/uiDesigner.xml
34+
.idea/**/dbnavigator.xml
35+
36+
# Gradle
37+
.idea/**/gradle.xml
38+
.idea/**/libraries
39+
40+
# Gradle and Maven with auto-import
41+
# When using Gradle or Maven with auto-import, you should exclude module files,
42+
# since they will be recreated, and may cause churn. Uncomment if using
43+
# auto-import.
44+
# .idea/artifacts
45+
# .idea/compiler.xml
46+
# .idea/jarRepositories.xml
47+
# .idea/modules.xml
48+
# .idea/*.iml
49+
# .idea/modules
50+
# *.iml
51+
# *.ipr
52+
53+
# CMake
54+
cmake-build-*/
55+
56+
# Mongo Explorer plugin
57+
.idea/**/mongoSettings.xml
58+
59+
# File-based project format
60+
*.iws
61+
62+
# IntelliJ
63+
out/
64+
65+
# mpeltonen/sbt-idea plugin
66+
.idea_modules/
67+
68+
# JIRA plugin
69+
atlassian-ide-plugin.xml
70+
71+
# Cursive Clojure plugin
72+
.idea/replstate.xml
73+
74+
# Crashlytics plugin (for Android Studio and IntelliJ)
75+
com_crashlytics_export_strings.xml
76+
crashlytics.properties
77+
crashlytics-build.properties
78+
fabric.properties
79+
80+
# Editor-based Rest Client
81+
.idea/httpRequests
82+
83+
# Android studio 3.1+ serialized cache file
84+
.idea/caches/build_file_checksums.ser
85+
86+
### PyCharm Patch ###
87+
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
88+
89+
# *.iml
90+
# modules.xml
91+
# .idea/misc.xml
92+
# *.ipr
93+
94+
# Sonarlint plugin
95+
# https://plugins.jetbrains.com/plugin/7973-sonarlint
96+
.idea/**/sonarlint/
97+
98+
# SonarQube Plugin
99+
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
100+
.idea/**/sonarIssues.xml
101+
102+
# Markdown Navigator plugin
103+
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
104+
.idea/**/markdown-navigator.xml
105+
.idea/**/markdown-navigator-enh.xml
106+
.idea/**/markdown-navigator/
107+
108+
# Cache file creation bug
109+
# See https://youtrack.jetbrains.com/issue/JBR-2257
110+
.idea/$CACHE_FILE$
111+
112+
# CodeStream plugin
113+
# https://plugins.jetbrains.com/plugin/12206-codestream
114+
.idea/codestream.xml
115+
116+
### Python ###
117+
# Byte-compiled / optimized / DLL files
118+
__pycache__/
119+
*.py[cod]
120+
*$py.class
121+
122+
# C extensions
123+
*.so
124+
125+
# Distribution / packaging
126+
.Python
127+
build/
128+
develop-eggs/
129+
dist/
130+
downloads/
131+
eggs/
132+
.eggs/
133+
lib/
134+
lib64/
135+
parts/
136+
sdist/
137+
var/
138+
wheels/
139+
pip-wheel-metadata/
140+
share/python-wheels/
141+
*.egg-info/
142+
.installed.cfg
143+
*.egg
144+
MANIFEST
145+
146+
# PyInstaller
147+
# Usually these files are written by a python script from a template
148+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
149+
*.manifest
150+
*.spec
151+
152+
# Installer logs
153+
pip-log.txt
154+
pip-delete-this-directory.txt
155+
156+
# Unit test / coverage reports
157+
htmlcov/
158+
.tox/
159+
.nox/
160+
.coverage
161+
.coverage.*
162+
.cache
163+
nosetests.xml
164+
coverage.xml
165+
*.cover
166+
*.py,cover
167+
.hypothesis/
168+
.pytest_cache/
169+
pytestdebug.log
170+
171+
# Translations
172+
*.mo
173+
*.pot
174+
175+
# Django stuff:
176+
*.log
177+
local_settings.py
178+
db.sqlite3
179+
db.sqlite3-journal
180+
181+
# Flask stuff:
182+
instance/
183+
.webassets-cache
184+
185+
# Scrapy stuff:
186+
.scrapy
187+
188+
# Sphinx documentation
189+
docs/_build/
190+
doc/_build/
191+
192+
# PyBuilder
193+
target/
194+
195+
# Jupyter Notebook
196+
.ipynb_checkpoints
197+
198+
# IPython
199+
profile_default/
200+
ipython_config.py
201+
202+
# pyenv
203+
.python-version
204+
205+
# pipenv
206+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
207+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
208+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
209+
# install all needed dependencies.
210+
#Pipfile.lock
211+
212+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
213+
__pypackages__/
214+
215+
# Celery stuff
216+
celerybeat-schedule
217+
celerybeat.pid
218+
219+
# SageMath parsed files
220+
*.sage.py
221+
222+
# Environments
223+
.env
224+
.venv
225+
env/
226+
venv/
227+
ENV/
228+
env.bak/
229+
venv.bak/
230+
231+
# Spyder project settings
232+
.spyderproject
233+
.spyproject
234+
235+
# Rope project settings
236+
.ropeproject
237+
238+
# mkdocs documentation
239+
/site
240+
241+
# mypy
242+
.mypy_cache/
243+
.dmypy.json
244+
dmypy.json
245+
246+
# Pyre type checker
247+
.pyre/
248+
249+
# pytype static type analyzer
250+
.pytype/
251+
252+
#!! ERROR: sublime is undefined. Use list command to see defined gitignore types !!#
253+
254+
# End of https://www.toptal.com/developers/gitignore/api/python,pycharm,code,sublime

README.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,50 @@
1-
# allokation
2-
Allocate your money to have equal distribution between the stocks you want in your portfolio
1+
# Welcome to Allokation 👋
2+
3+
![Version](https://img.shields.io/badge/version-0.0.1-blue.svg?cacheSeconds=2592000)
4+
![License](https://img.shields.io/badge/License-MIT-yellow.svg)
5+
6+
> A python package that gets stocks prices from yahoo and calculates how much of each stocks you must buy to have almost equal distribution between the stocks you want in your portfolio
7+
8+
## Requires
9+
10+
python >= 3.x
11+
12+
## Install
13+
14+
- clone the repository
15+
16+
```sh
17+
git clone [email protected]:capaci/allokation.git
18+
```
19+
20+
- install dependencies
21+
22+
```sh
23+
pip install -r requirements.txt
24+
```
25+
26+
## Usage
27+
28+
Check the example available in [`example/example.py`](./example/example.py)
29+
30+
## Run tests
31+
32+
```sh
33+
pytest
34+
```
35+
36+
## Author
37+
38+
👤 **Rafael Capaci**
39+
40+
- Website: [capaci.dev](https://capaci.dev)
41+
- Twitter: [@capacirafael](https://twitter.com/capacirafael)
42+
- Github: [@capaci](https://github.com/capaci)
43+
- LinkedIn: [@rafaelcapaci](https://linkedin.com/in/rafaelcapaci)
44+
45+
## Show your support
46+
47+
Give a ⭐️ if this project helped you!
48+
49+
***
50+
_This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_

allokation/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from .functions import (
2+
get_closing_price_from_yahoo,
3+
map_columns_without_suffix,
4+
transpose_prices,
5+
calculate_multiplier,
6+
calculate_amount,
7+
calculate_total_for_each_ticker,
8+
calculate_percentage_of_each_ticker
9+
)
10+
11+
__all__ = [
12+
'get_closing_price_from_yahoo',
13+
'map_columns_without_suffix',
14+
'transpose_prices',
15+
'calculate_multiplier',
16+
'calculate_amount',
17+
'calculate_total_for_each_ticker',
18+
'calculate_percentage_of_each_ticker'
19+
]

allokation/functions.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import pandas as pd
2+
from pandas_datareader import data as web
3+
4+
5+
def get_closing_price_from_yahoo(tickers, date):
6+
result = web.get_data_yahoo(tickers, date)
7+
return result['Adj Close']
8+
9+
10+
def map_columns_without_suffix(tickers):
11+
return {ticker: ticker[:-3] for ticker in tickers}
12+
13+
14+
def transpose_prices(prices):
15+
df = pd.DataFrame()
16+
df['symbol'] = prices.columns
17+
df['price'] = prices.values[0]
18+
df = df.round(2)
19+
return df
20+
21+
22+
def calculate_multiplier(df, number_of_tickers, available_money):
23+
max_price = df['price'].max()
24+
percentage = 1 / number_of_tickers
25+
multiplier = (available_money * percentage) / max_price
26+
return multiplier
27+
28+
29+
def calculate_amount(df, multiplier):
30+
return (df['price'].max()*multiplier/df['price']).round(0)
31+
32+
33+
def calculate_total_for_each_ticker(df):
34+
return df['price']*df['amount']
35+
36+
37+
def calculate_percentage_of_each_ticker(df):
38+
return df['total']/df['total'].sum() * 100

0 commit comments

Comments
 (0)