Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import plotly.graph_objects as go
- import csv
- from datetime import datetime
- # load data file
- qqq_data = []
- with open('qqq.csv', 'r') as file:
- reader = csv.DictReader(file)
- for row in reader:
- qqq_data.append({
- 'date': datetime.strptime(row['date'], '%Y-%m-%d'),
- 'close': float(row['close'])
- })
- # set tqqq ipo price and last record
- tqqq_price = 0.4325520098209381
- tqqq_data = [{'date': qqq_data[-1]['date'], 'close': tqqq_price}]
- # calculate % change to find previous day closing price
- daily_expense_ratio = 0.88 / 100 / 252
- for i in range(len(qqq_data) - 1, 0, -1):
- percent_change = (qqq_data[i]['close'] - qqq_data[i-1]['close']) / qqq_data[i-1]['close']
- tqqq_price /= (1 + 3 * percent_change) * (1 + daily_expense_ratio)
- tqqq_data.append({'date': qqq_data[i-1]['date'], 'close': tqqq_price})
- tqqq_data.reverse()
- # Save to a CSV file
- df = pd.DataFrame(tqqq_data)
- df.to_csv("tqqq.csv", index=False)
- # Find highest and lowest closing prices
- min_row = df.loc[df['close'].idxmin()]
- min_value = min_row['close']
- min_date = min_row['date']
- max_row = df.loc[df['close'].idxmax()]
- max_value = max_row['close']
- max_date = max_row['date']
- print(f"Lowest value: {min_value} on {min_date}")
- print(f"Highest value: {max_value} on {max_date}")
- # Visualize the tqqq closing prices
- fig = go.Figure()
- fig.add_trace(go.Scatter(x=df['date'], y=df['close'], mode='lines', name='Close'))
- fig.add_trace(go.Scatter(
- x=[min_date], y=[min_value],
- mode='markers+text',
- name='Lowest',
- text=['Lowest'],
- textposition='bottom center',
- marker=dict(color='red', size=10)
- ))
- fig.add_trace(go.Scatter(
- x=[max_date], y=[max_value],
- mode='markers+text',
- name='Highest',
- text=['Highest'],
- textposition='top center',
- marker=dict(color='green', size=10)
- ))
- fig.update_layout(
- title='TQQQ Close Prices with Highest and Lowest Points',
- xaxis_title='Date',
- yaxis_title='Close Price',
- showlegend=True
- )
- fig.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement