In [1]:
import pandas as pd
import numpy as np
import yfinance as yf
import random
from matplotlib import pyplot as plt
import seaborn as sns
import warnings
import secrets
import plotly as plotly
import plotly.express as px
from tqdm import tqdm
import plotly.graph_objects as go
pd.set_option('plotting.backend', 'matplotlib')
plotly.offline.init_notebook_mode()
#warnings.simplefilter(action='ignore', category=FutureWarning
import plotly.io as pio
plotly_template = pio.templates["plotly_dark"]
plt.style.use('dark_background')
pd.set_option('plotting.backend', 'plotly')
Is it better to disinvest in a stock when it is in profit or in a loss?
In [2]:
T = 30
STARTING_CAPITAL = 10000
TICKERS = ['AAPL', 'MSFT', 'GOOGL', 'AMZN','TSLA', 'NVDA', 'PYPL', 'ADBE', 'INTC']
#import all ticker data
df_Tickers={x: yf.download(x)["Adj Close"].dropna() for x in TICKERS}
df_Tickers_pct_change = {x: df_Tickers[x].pct_change(T) for x in TICKERS}
[*********************100%%**********************] 1 of 1 completed [*********************100%%**********************] 1 of 1 completed [*********************100%%**********************] 1 of 1 completed [*********************100%%**********************] 1 of 1 completed [*********************100%%**********************] 1 of 1 completed [*********************100%%**********************] 1 of 1 completed [*********************100%%**********************] 1 of 1 completed [*********************100%%**********************] 1 of 1 completed [*********************100%%**********************] 1 of 1 completed
In [2]:
In [3]:
from Code_base import *
Portfolio = Portfolio(code="1",assets=TICKERS, cash=STARTING_CAPITAL,weights=None)
print(Portfolio.weights)
[0.58296093 0.41703907] [0.18619373 0.00762633 0.05382089 0.11853879 0.05717692 0.18142175 0.1351871 0.19605544 0.06397905]
In [ ]:
!jupyter nbconvert --to html Portfolio2.ipynb --HTMLExporter.theme=dark
In [4]:
In [4]: