-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a way to define the percentages wanted for each stock
- Loading branch information
Showing
6 changed files
with
90 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,28 @@ | ||
from allokation.utils import (calculate_amount, calculate_multiplier, | ||
from allokation.utils import (calculate_amount, | ||
calculate_percentage_of_each_ticker, | ||
calculate_total_for_each_ticker, | ||
get_closing_price_from_yahoo, get_target_date, | ||
map_columns_without_suffix, transpose_prices) | ||
get_closing_price_from_yahoo, | ||
get_percentage_of_stocks, get_target_date, | ||
transpose_prices) | ||
|
||
|
||
def allocate_money(available_money, tickers): | ||
# import ipdb; ipdb.set_trace() | ||
def allocate_money(available_money, tickers, percentages=None): | ||
if percentages and len(tickers) != len(percentages): | ||
raise Exception('Tickers and percentages must have the same lenght') | ||
|
||
percentage_multiplier = get_percentage_of_stocks(tickers=tickers, percentages=percentages) | ||
|
||
target_date = get_target_date() | ||
prices = get_closing_price_from_yahoo(tickers=tickers, date=target_date) | ||
renamed_columns = map_columns_without_suffix(tickers) | ||
prices.rename(columns=renamed_columns, inplace=True) | ||
df = transpose_prices(prices) | ||
multiplier = calculate_multiplier(df, number_of_tickers=len(tickers), available_money=available_money) | ||
|
||
df['amount'] = calculate_amount(df, multiplier) | ||
df['amount'] = calculate_amount(df, available_money, percentage_multiplier) | ||
|
||
df['total'] = calculate_total_for_each_ticker(df) | ||
df['percentage'] = calculate_percentage_of_each_ticker(df) | ||
|
||
result = {} | ||
result['allocations'] = df.set_index('symbol').T.to_dict() | ||
result['total_value'] = df["total"].sum() | ||
result['total_value'] = df["total"].sum().round(2) | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters