Skip to content

Commit ad364d7

Browse files
committed
New STuff
1 parent 5a9aedb commit ad364d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1499
-2
lines changed

.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/Python.iml

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Adv_Pyth/Aya.py

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
import yfinance as yf
2+
import numpy as np
3+
import pandas as pd
4+
from sklearn.cluster import KMeans
5+
6+
tickers = ['AAPL', 'MSFT', 'GOOGL', 'AMZN', 'META', 'TSLA', 'NFLX', 'NVDA']
7+
8+
stock_dt = yf.download(tickers, start="2023-09-01", end="2024-09-01", group_by='ticker')
9+
stock_prices = []
10+
for ticker in tickers:
11+
closing_prices = stock_dt[ticker]['Close'].values[:200]
12+
stock_prices.append(closing_prices)
13+
stock_prices_numpyy = np.array(stock_prices)
14+
print(stock_prices_numpyy.shape)
15+
16+
17+
# Date
18+
stock_dt.index = pd.to_datetime(stock_dt.index)
19+
20+
# Monthly averages, max and mins
21+
def calculate_monthly_stats():
22+
monthly_stats = {}
23+
for ticker in tickers:
24+
# Group data in month and calc mean max min
25+
monthly_data = stock_dt[ticker]['Close'].resample('M').agg(['mean', 'max', 'min'])
26+
monthly_stats[ticker] = monthly_data
27+
return monthly_stats
28+
29+
30+
#Task3 daily price change
31+
def calculate_the_daily_share_price_change():
32+
daily_returns={}
33+
for ticker in tickers:
34+
daily_returns[ticker]=stock_dt[ticker]['Close'].pct_change().dropna()
35+
return daily_returns
36+
37+
daily_returns=calculate_the_daily_share_price_change()
38+
39+
40+
#Task3 highest share price change
41+
def highest_single_day_changes():
42+
highest_increase={}
43+
highest_decrease={}
44+
45+
for ticker in tickers:
46+
highest_decrease[ticker]=daily_returns[ticker].idxmin(), daily_returns[ticker].min()
47+
highest_increase[ticker]=daily_returns[ticker].idxmax(), daily_returns[ticker].max()
48+
49+
return highest_decrease, highest_increase
50+
51+
highest_decrease,highest_increase=highest_single_day_changes()
52+
print("The highest single day price increases: ")
53+
54+
for ticker, (date, change) in highest_increase.items():
55+
print(f"{ticker} {date} with increase of {change:.2%}")
56+
57+
print("\nHighest single day decrease ")
58+
59+
for ticker,(date, change) in highest_decrease.items():
60+
print(f"{ticker}:{date} with decrease of {change:.2%}")
61+
62+
volatility = {ticker: np.std(daily_returns[ticker]) for ticker in daily_returns.keys()}
63+
most_volatile_element_ticker=max(volatility,key=volatility.get)
64+
65+
print(f"\nMost Volatile stock: {most_volatile_element_ticker} with volatility {volatility[most_volatile_element_ticker]:.4f}")
66+
67+
#Task 4
68+
def cluster_stocks(number_clusters=3):
69+
the_returned_matrix=np.array([daily_returns[ticker] for ticker in tickers])
70+
kmeans_algorithm=KMeans(n_clusters=number_clusters, random_state=42)
71+
kmeans_algorithm.fit(the_returned_matrix)
72+
return kmeans_algorithm.labels_
73+
74+
the_stock_clusters=cluster_stocks(number_clusters=3)
75+
76+
print("Stock Clusters")
77+
78+
for ticker,cluster in zip(tickers, the_stock_clusters):
79+
print(f"{ticker} is within the cluster {cluster}")
80+
81+
monthly_stats = calculate_monthly_stats()
82+
for ticker, stats in monthly_stats.items():
83+
print(f"{ticker} Monthly Stats:\n", stats)
84+
85+
# Find how many days Tesla stock was above $500
86+
def days_above_500(ticker, threshold=500):
87+
above_threshold = stock_dt[ticker]['Close'][stock_dt[ticker]['Close'] > threshold].count()
88+
return above_threshold
89+
90+
tesla_above_500 = days_above_500('TSLA', 500)
91+
print(f"The tesla share price was above $500 on {tesla_above_500} days.")
92+
93+
def find_top_5_days(ticker):
94+
top5days = stock_dt[ticker]['Close'].nlargest(5)
95+
return top5days
96+
97+
for ticker in tickers:
98+
top_5 = find_top_5_days(ticker)
99+
print(f"Top 5 days for {ticker}:\n", top_5)
100+
101+
102+
103+
def high_and_low():
104+
highest_price = stock_dt.xs('Close', level=1, axis=1).idxmax(axis=1)
105+
lowest_price = stock_dt.xs('Close', level=1, axis=1).idxmin(axis=1)
106+
return highest_price, lowest_price
107+
108+
highest_price, lowest_price = high_and_low()
109+
print(f"Company with highest prices on each day:\n{highest_price}")
110+
print(f"Company with lowest prices on each day:\n{lowest_price}")
111+
112+
#Task 4
113+
company_idx = 2
114+
google_prices = stock_prices_numpyy[company_idx, :]
115+
116+
117+
#Task 5 finding the mean and std and generate 200 values
118+
the_mean = np.mean(google_prices)
119+
standard_deviation = np.std(google_prices)
120+
new_stock_prices = np.random.normal(the_mean, standard_deviation, 200)
121+
new_stock_prices= new_stock_prices.reshape(1,-1)
122+
updated_stock_share_price = np.concatenate((stock_prices_numpyy, new_stock_prices))
123+
print("Updated stock share price shape: ",updated_stock_share_price.shape)
124+
125+
126+
#Task 6 META
127+
company_idx = 4
128+
meta_share_price = stock_prices_numpyy[company_idx, :]
129+
130+
meta_share_price_changes = np.diff(meta_share_price)/meta_share_price[:-1]
131+
132+
## mean
133+
mean_percent_diff = np.mean(meta_share_price_changes)
134+
standard_percent_change = np.std(meta_share_price_changes)
135+
136+
#daily percentage
137+
number_of_days=30
138+
forecast_percent_difference= np.random.normal(mean_percent_diff, standard_percent_change, number_of_days)
139+
140+
141+
forecasted_prices = [meta_share_price[-1]]
142+
143+
for standard_percent_change in forecast_percent_difference:
144+
upcoming_price= forecasted_prices[-1]*(1+standard_percent_change)
145+
forecasted_prices.append(upcoming_price)
146+
147+
forecasted_prices = np.array(forecasted_prices[1:])
148+
149+
print("The predicted price of Meta is for the next 30 days: ")
150+
print(forecasted_prices)
151+
152+
predicted_days_in_time = pd.date_range(start=stock_dt.index[-1],periods=number_of_days, freq='D')
153+
predicted_data_frame = pd.DataFrame({'Date': predicted_days_in_time, 'Predicted Share Price': forecasted_prices})
154+
155+
156+
print(predicted_data_frame)
157+
158+
159+
#saved file
160+
np.savetxt("file.txt",stock_prices_numpyy)

Amine/EvenOdd.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
pos=0
2+
neg=0
3+
odd=0
4+
even=0
5+
while(True):
6+
num=int(input("Please enter a number"))
7+
if(num != 0):
8+
if(num>0):
9+
pos+=1
10+
elif(num<0):
11+
neg+=1
12+
if(num%2==0):
13+
even+=1
14+
elif(num%2!=0):
15+
odd+=1
16+
else:
17+
break
18+
print(f"Positive Number: {pos}, Negative Number: {neg}, Odd Number: {odd}, Even Number: {even}")
19+

Amine/Part1.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
for i in range(1,11, 1):
2+
#range([start,stop),step)
3+
print(i)
4+
5+
def factorial(i):
6+
if(i<1):
7+
return "Factorial cannot be negative"
8+
if(i==1 or i==0):
9+
return 1
10+
else:
11+
return i*factorial(i-1)
12+
print(factorial(6))
13+
14+
15+
def squarenumb(nums):
16+
squares = []
17+
for num in nums :
18+
squares.append(num*num)
19+
return squares
20+
21+
22+
print(squarenumb([5,6,8,8,9]))

Aya22.py

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import math
2+
#function
3+
def factorial(num):
4+
if(num == 1):
5+
return 1
6+
else:
7+
x = num * (num-1)
8+
return x
9+
print(factorial(4))
10+
def factorial2(num2):
11+
for i in range(1, num2):
12+
num2 = num2*i
13+
return num2
14+
15+
mylist1=[1,2,3]
16+
def calc_average(mylist1):
17+
for i in mylist1:
18+
sum56=sum(mylist1)
19+
average = sum56/len(mylist1)
20+
return average
21+
print(calc_average(mylist1))
22+
23+
def fahrenheit(celsius):
24+
f= (9/5*celsius)+32
25+
return f
26+
27+
def add_two_number(num1=2, num2=3):
28+
return num1+num2
29+
30+
print(add_two_number(3))
31+
print(add_two_number(2,7))
32+
print(add_two_number())
33+
34+
#glo
35+
num33=8
36+
#local scope
37+
def local_global_scope():
38+
global num7
39+
num7 = 8
40+
num1=3
41+
return num1
42+
43+
local_global_scope()
44+
45+
def print_stars(): #down
46+
num = int(input("Enter a number"))
47+
for i in range(1, num+1):
48+
for j in range(i):
49+
print("*",end=' ')
50+
print()
51+
return ""
52+
53+
def print_stars_up(): #down
54+
num = int(input("Enter a number"))
55+
for i in range(num,0,-1):
56+
for j in range(i):
57+
print("*",end=' ')
58+
print()
59+
return ""
60+
print(print_stars())
61+
print(print_stars_up())

Loops/Arraylooping.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
print("Here are the numbers that are still available from 1 through 20 that you can take")
33
for n in range (1,20):
44
if n in numbersTaken:
5-
continue
6-
print(n)
5+
print(n)

Loops/ForLoop.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
mylist3=["Zakaria", "Omar", "Youssef", "Nour", "Younes"]
2+
3+
#Quand tu sais combien d'elements il y a dans une structure de donnees tu utilise un for loop
4+
for i in mylist3:
5+
print(i,end=" ")
6+
print("YOUPI")
7+
8+
#Quand tu ne sais pas tu utilise une while loop.

Loops/Salma.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from time import sleep
2+
#from library import a function from a library give me a book of functionalities
3+
4+
start = int(input("Please enter a number to start counting from:"))
5+
6+
#for counter in range(start, stop, step)
7+
# start at the number stop at negative 1 and step down 1 number every time [start,stop) [-7, 6
8+
for counter in range(start, -1, -1):
9+
print(counter)
10+
sleep(2) #run every second
11+
12+
list1=["Salma","Nidal","Aya","Imane","Omar"]
13+
list2=["Salma", "Houda","Nisrine","Nisrine","Bouchra","Yousra","Aya", "Aya","Aya","Nisrine","Nisrine","Nisrine","Nisrine","Nisrine","Nisrine"]
14+
15+
for element in set(list2):
16+
print(element)
17+
18+
19+
for x in list1:
20+
print(x)
21+
22+
while(x != 3):
23+
input(str("Name"))
24+
x = int(input("Number: "))
25+
26+
y=int(input("Please Enter a number"))
27+
if(y != 6):
28+
print("Not 6")
29+
else:
30+
print("Found")

0 commit comments

Comments
 (0)