0% found this document useful (0 votes)
26 views9 pages

Airbnbsp

The document analyzes stock market data for Airbnb (ABNB) from 2020 to 2024. It performs data preprocessing, exploratory data analysis including plotting prices and calculating statistics, calculates daily returns and volatility, analyzes moving averages, backtests a trading strategy, and explores volume and an event study.

Uploaded by

BHAI LOG
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views9 pages

Airbnbsp

The document analyzes stock market data for Airbnb (ABNB) from 2020 to 2024. It performs data preprocessing, exploratory data analysis including plotting prices and calculating statistics, calculates daily returns and volatility, analyzes moving averages, backtests a trading strategy, and explores volume and an event study.

Uploaded by

BHAI LOG
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

airbnbsp

May 5, 2024

Data Preprocessing
[6]: import pandas as pd
df = pd.read_csv("C:/Users/KIIT/Downloads/abnb_stock_data.csv")
df

[6]: Date Open High Low Close Adj Close \


0 2020-12-10 146.000000 165.000000 141.250000 144.710007 144.710007
1 2020-12-11 146.550003 151.500000 135.100006 139.250000 139.250000
2 2020-12-14 135.000000 135.300003 125.160004 130.000000 130.000000
3 2020-12-15 126.690002 127.599998 121.500000 124.800003 124.800003
4 2020-12-16 125.830002 142.000000 124.910004 137.990005 137.990005
.. … … … … … …
804 2024-02-23 153.270004 155.300003 150.824997 152.660004 152.660004
805 2024-02-26 149.960007 150.179993 148.559998 149.270004 149.270004
806 2024-02-27 150.000000 152.470001 149.229996 152.059998 152.059998
807 2024-02-28 152.029999 154.899994 151.789993 153.429993 153.429993
808 2024-02-29 153.399994 160.000000 153.220001 157.470001 157.470001

Volume
0 70447500
1 26980800
2 16966100
3 10914400
4 20409600
.. …
804 4851100
805 5277900
806 4623700
807 4329100
808 8002300

[809 rows x 7 columns]

[8]: df.head()

[8]: Date Open High Low Close Adj Close \


0 2020-12-10 146.000000 165.000000 141.250000 144.710007 144.710007

1
1 2020-12-11 146.550003 151.500000 135.100006 139.250000 139.250000
2 2020-12-14 135.000000 135.300003 125.160004 130.000000 130.000000
3 2020-12-15 126.690002 127.599998 121.500000 124.800003 124.800003
4 2020-12-16 125.830002 142.000000 124.910004 137.990005 137.990005

Volume
0 70447500
1 26980800
2 16966100
3 10914400
4 20409600

[10]: df.tail()

[10]: Date Open High Low Close Adj Close \


804 2024-02-23 153.270004 155.300003 150.824997 152.660004 152.660004
805 2024-02-26 149.960007 150.179993 148.559998 149.270004 149.270004
806 2024-02-27 150.000000 152.470001 149.229996 152.059998 152.059998
807 2024-02-28 152.029999 154.899994 151.789993 153.429993 153.429993
808 2024-02-29 153.399994 160.000000 153.220001 157.470001 157.470001

Volume
804 4851100
805 5277900
806 4623700
807 4329100
808 8002300

Exploratory Data Analysis (EDA)

[14]: import matplotlib.pyplot as plt

# Plot the closing prices over time


df['Close'].plot(figsize=(12, 6), title='Airbnb (ABNB) Closing Prices')
plt.show()

2
[16]: # Calculate summary statistics
print(df.describe())

Open High Low Close Adj Close \


count 809.000000 809.000000 809.000000 809.000000 809.000000
mean 139.490291 142.570870 136.535424 139.619407 139.619407
std 28.325750 29.216124 27.395624 28.233642 28.233642
min 82.970001 84.250000 81.910004 82.489998 82.489998
25% 117.510002 119.699997 115.199997 117.110001 117.110001
50% 139.250000 141.539993 136.539993 139.419998 139.419998
75% 159.500000 164.699997 155.699997 160.250000 160.250000
max 216.240005 219.940002 209.089996 216.839996 216.839996

Volume
count 8.090000e+02
mean 6.489790e+06
std 5.239688e+06
min 1.995400e+06
25% 4.090600e+06
50% 5.189000e+06
75% 7.136800e+06
max 7.478640e+07
Return Analysis
[18]: # Calculate daily returns
df['Daily_Return'] = df['Close'].pct_change()

3
[22]: df

[22]: Date Open High Low Close Adj Close \


0 2020-12-10 146.000000 165.000000 141.250000 144.710007 144.710007
1 2020-12-11 146.550003 151.500000 135.100006 139.250000 139.250000
2 2020-12-14 135.000000 135.300003 125.160004 130.000000 130.000000
3 2020-12-15 126.690002 127.599998 121.500000 124.800003 124.800003
4 2020-12-16 125.830002 142.000000 124.910004 137.990005 137.990005
.. … … … … … …
804 2024-02-23 153.270004 155.300003 150.824997 152.660004 152.660004
805 2024-02-26 149.960007 150.179993 148.559998 149.270004 149.270004
806 2024-02-27 150.000000 152.470001 149.229996 152.059998 152.059998
807 2024-02-28 152.029999 154.899994 151.789993 153.429993 153.429993
808 2024-02-29 153.399994 160.000000 153.220001 157.470001 157.470001

Volume Daily_Return
0 70447500 NaN
1 26980800 -0.037731
2 16966100 -0.066427
3 10914400 -0.040000
4 20409600 0.105689
.. … …
804 4851100 -0.016746
805 5277900 -0.022206
806 4623700 0.018691
807 4329100 0.009010
808 8002300 0.026331

[809 rows x 8 columns]

Volatility Analysis
[24]: # Calculate daily volatility (standard deviation of daily returns)
daily_volatility = df['Daily_Return'].std()
print(f"Daily Volatility: {daily_volatility}")

Daily Volatility: 0.03302080425585316

[25]: # Calculate ATR (Average True Range)


atr = df['High'] - df['Low']
atr = atr.rolling(14).mean()
print(atr.tail())

804 4.981215
805 4.831215
806 4.907072
807 4.778500
808 5.076357

4
dtype: float64
Moving Averages
[27]: # Calculate 20-day and 50-day moving averages
df['MA_20'] = df['Close'].rolling(window=20).mean()
df['MA_50'] = df['Close'].rolling(window=50).mean()

[29]: df['MA_20']

[29]: 0 NaN
1 NaN
2 NaN
3 NaN
4 NaN

804 149.61325
805 149.59575
806 149.56375
807 149.76325
808 150.42975
Name: MA_20, Length: 809, dtype: float64

[32]: df['MA_50']

[32]: 0 NaN
1 NaN
2 NaN
3 NaN
4 NaN

804 143.7221
805 143.8965
806 144.0475
807 144.1709
808 144.3883
Name: MA_50, Length: 809, dtype: float64

[34]: # Plot the closing prices and moving averages


df[['Close', 'MA_20', 'MA_50']].plot(figsize=(12, 6), title='Airbnb (ABNB)␣
↪Closing Prices and Moving Averages')

plt.show()

5
Trading Strategy Backtesting
[36]: # Define a simple moving average crossover strategy
df['Signal'] = 0
df.loc[df['MA_20'] > df['MA_50'], 'Signal'] = 1 # Buy signal
df.loc[df['MA_20'] < df['MA_50'], 'Signal'] = -1 # Sell signal

[38]: # Calculate strategy returns


df['Strategy_Returns'] = df['Signal'].shift(1) * df['Daily_Return']

[40]: df['Strategy_Returns']

[40]: 0 NaN
1 -0.000000
2 -0.000000
3 -0.000000
4 0.000000

804 -0.016746
805 -0.022206
806 0.018691
807 0.009010
808 0.026331
Name: Strategy_Returns, Length: 809, dtype: float64

[42]: # Calculate cumulative returns


cumulative_returns = (1 + df['Strategy_Returns']).cumprod()
print(cumulative_returns.tail())

6
804 0.518918
805 0.507395
806 0.516879
807 0.521536
808 0.535268
Name: Strategy_Returns, dtype: float64
Volume Analysis
[46]: # Calculate the average daily volume
avg_daily_volume = df['Volume'].mean()
print(f"Average Daily Volume: {avg_daily_volume}")

Average Daily Volume: 6489789.864029666

[48]: # Plot the closing prices and trading volume


fig, ax1 = plt.subplots(figsize=(12, 6))
ax1.plot(df.index, df['Close'], label='Close')
ax1.set_ylabel('Price (USD)')
ax1.legend(loc='upper left')

ax2 = ax1.twinx()
ax2.bar(df.index, df['Volume'], alpha=0.3, label='Volume')
ax2.set_ylabel('Volume')
ax2.legend(loc='upper right')

plt.show()

Event Study

7
[50]: # Define the event date
event_date = pd.Timestamp('2023-02-15')

[53]: # Create an event window


event_window = pd.DateOffset(days=30)
start_date = event_date - event_window
end_date = event_date + event_window

[55]: event_window

[55]: <DateOffset: days=30>

[61]: start_date

[61]: Timestamp('2023-01-16 00:00:00')

Monte Carlo Simulation


[63]: import numpy as np

# Define the initial stock price


initial_price = df['Close'].iloc[-1]

[65]: initial_price

[65]: 157.47000122070312

[67]: # Set the simulation parameters


num_simulations = 10000
num_days = 252 # One trading year
drift = 0.1 # Assumed annual drift (10%)
volatility = df['Daily_Return'].std() * np.sqrt(252) # Annualized volatility

[69]: volatility

[69]: 0.5241890169139842

[71]: # Run the Monte Carlo simulation


simulated_prices = np.zeros((num_simulations, num_days))
simulated_prices[:, 0] = initial_price

for i in range(num_simulations):
for j in range(1, num_days):
simulated_prices[i, j] = simulated_prices[i, j - 1] * np.exp((drift - 0.
↪5 * volatility ** 2) / 252 +

volatility␣
↪* np.sqrt(1 / 252) * np.random.normal())

8
[74]: # Plot the simulated price distributions
plt.figure(figsize=(12, 6))
plt.hist(simulated_prices[:, -1], bins=50, density=True, label='Simulated␣
↪Prices')

plt.axvline(initial_price, color='r', linestyle='--', label='Initial Price')


plt.xlabel('Price (USD)')
plt.ylabel('Density')
plt.title('Monte Carlo Simulation of Airbnb Stock Prices')
plt.legend()
plt.show()

[ ]:

You might also like