In [ ]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
In [ ]:
# we can use sin/cos to model the demand of christmas tree
In [ ]:
#visualize sin
x = np.linspace(0,10,50)
y = np.sin(x)
plt.figure(figsize=(10,3))
plt.plot(x,y, linewidth= 3, color='magenta')
plt.show()
In [ ]:
#manually create function. dates is the input dates, a is smallest demand, b is the extent of the demand, phi is how we adjust the pattern
def xmax_demand(dates, a= 1, b= 1, phi= np.pi*(3/4)):
doy= dates.dayofyear
demand= a + b* np.sin(2*np.pi*doy/365 + phi)
return demand
In [ ]:
#give the function data
dates= pd.date_range('2024-01-01', '2025-01-01', freq='D')
demand =xmax_demand(dates)
In [ ]:
#visualize
plt.figure(figsize=(10,3))
plt.plot(dates, demand, linewidth= 3, linestyle=':', color='darkgreen')
plt.grid()
plt.axhline(y=0, color= 'red', linestyle='--')
plt.axhline(y=2, color= 'red', linestyle='--')
plt.axhline(y=1, color='orange', linestyle='--')
plt.xticks(pd.date_range(dates.min(), dates.max(), freq='MS'), rotation=45)
plt.xlabel('Date')
plt.ylabel('Demand')
plt.title('Christmas Tree Demand')
plt.show()
In [ ]:
date_test=pd.to_datetime('2025-05-10') #using my bday
date_test.dayofyear
Out[ ]:
130
In [ ]:
In [ ]:
!jupyter nbconvert --to html bana310_110625.ipynb
[NbConvertApp] Converting notebook bana310_final.ipynb to html [NbConvertApp] WARNING | Alternative text is missing on 14 image(s). [NbConvertApp] Writing 963726 bytes to bana310_final.html