Skip to content

Commit

Permalink
changes to api communication
Browse files Browse the repository at this point in the history
  • Loading branch information
eethansmith committed Dec 5, 2023
1 parent 55fdcd8 commit ee73b6d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions backend/data/investments_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@
"Price per Share USD": "$39.44",
"Image Filename": "IMG_2165.PNG",
"Transaction Valuation USD": 223.0905473376,
"Overall Holdings": 8.881784197001252e-16,
"Overall Holdings": 0.0,
"Average Cost per Share USD": 27.91461712979707,
"Realized Gain/Loss USD": 65.19279849870615,
"Portfolio Valuation USD": 2470.1131512486995
Expand Down Expand Up @@ -848,7 +848,7 @@
"Price per Share USD": "$57.01",
"Image Filename": "IMG_2167.PNG",
"Transaction Valuation USD": 27.6601762213,
"Overall Holdings": -5.551115123125783e-17,
"Overall Holdings": 0.0,
"Average Cost per Share USD": 54.598688512473686,
"Realized Gain/Loss USD": 1.169922832299997,
"Portfolio Valuation USD": 2611.8061082888994
Expand Down Expand Up @@ -1142,7 +1142,7 @@
"Price per Share USD": "$37.91",
"Image Filename": "IMG_2176.PNG",
"Transaction Valuation USD": 15.4107281366,
"Overall Holdings": 8.881784197001252e-16,
"Overall Holdings": 0.0,
"Average Cost per Share USD": 38.71999999999998,
"Realized Gain/Loss USD": -0.3292716905999923,
"Portfolio Valuation USD": 2595.6754597536997
Expand Down Expand Up @@ -1590,7 +1590,7 @@
"Price per Share USD": "$22.25",
"Image Filename": "IMG_2192.PNG",
"Transaction Valuation USD": 107.713481315,
"Overall Holdings": 8.881784197001252e-16,
"Overall Holdings": 0.0,
"Average Cost per Share USD": 69.04279673448227,
"Realized Gain/Loss USD": -226.52651850499993,
"Portfolio Valuation USD": 2684.3038206032998
Expand Down Expand Up @@ -1702,7 +1702,7 @@
"Price per Share USD": "$160.08",
"Image Filename": "IMG_2196.PNG",
"Transaction Valuation USD": 80.640524112,
"Overall Holdings": 1.1102230246251565e-16,
"Overall Holdings": 0.0,
"Average Cost per Share USD": 194.0918810701534,
"Realized Gain/Loss USD": -17.133532705723262,
"Portfolio Valuation USD": 2662.7805532620996
Expand Down
Binary file modified backend/myapp/__pycache__/graph_stock_holdings.cpython-38.pyc
Binary file not shown.
20 changes: 10 additions & 10 deletions backend/myapp/graph_stock_holdings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,27 @@ def get_stock_history(request, ticker):

historical_values = []
current_shares = 0
current_average_cost_per_share = 0

# Before the loop, sort transactions by date
transactions.sort(key=lambda x: datetime.strptime(x["Date"], '%d-%m-%Y'))

for date, row in historical_prices.iterrows():
date = date.to_pydatetime().replace(tzinfo=None)
date = date.to_pydatetime().replace(tzinfo=None) # Make date timezone naive
current_shares = 0 # Reset current shares for each date

# Accumulate shares up to the current date
for transaction in transactions:
transaction_date = datetime.strptime(transaction["Date"], '%d-%m-%Y')

if transaction_date <= date:
shares = float(transaction["No. of Shares"])
if transaction["Transaction Type"] == "BUY":
current_shares += shares
current_average_cost_per_share = float(transaction["Average Cost per Share USD"])
elif transaction["Transaction Type"] == "SELL":
current_shares -= shares

# Calculate value for the current date
stock_worth = current_shares * row['Close']
stock_paid = current_average_cost_per_share * current_shares
historical_values.append({
"date": date.strftime('%Y-%m-%d'),
"stock_worth": stock_worth,
"stock_paid": stock_paid})
value = current_shares * row['Close']
historical_values.append({"date": date.strftime('%Y-%m-%d'), "value": value})

return JsonResponse(historical_values, safe=False)
2 changes: 1 addition & 1 deletion frontend/src/StockGraphing.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function StockGraph({ ticker }) { // Use destructuring to get the ticker prop
backgroundColor: 'rgba(245, 245, 245, 0.2)',
borderColor: 'rgb(245, 245, 245)',
borderWidth: 0.8,
tension: 0.08,
tension: 0.01,
pointRadius: 0,
hoverRadius: 0,
}]
Expand Down

0 comments on commit ee73b6d

Please sign in to comment.