import numpy as np # linear algebra
import pandas as pd # data processing, CSV file
import matplotlib.pyplot as plt
# URL of the dataset file on GitHub
url = 'https://raw.githubusercontent.com/TuvshinSelenge/Activision_Stock_Price_Analysis/main/steam.csv'
df = pd.read_csv(url)
# Drop the specified columns from the DataFrame
df = df.drop(['english', 'appid', 'required_age', 'categories', 'steamspy_tags', 'achievements', 'average_playtime', 'median_playtime', 'owners', 'platforms'], axis=1)
print(df.head())
name release_date developer publisher genres \ 0 Counter-Strike 2000-11-01 Valve Valve Action 1 Team Fortress Classic 1999-04-01 Valve Valve Action 2 Day of Defeat 2003-05-01 Valve Valve Action 3 Deathmatch Classic 2001-06-01 Valve Valve Action 4 Half-Life: Opposing Force 1999-11-01 Gearbox Software Valve Action positive_ratings negative_ratings price 0 124534 3339 7.19 1 3318 633 3.99 2 3416 398 3.99 3 1273 267 3.99 4 5250 288 3.99
#Filtering just the Activions games
activision_df = df.loc[df['publisher'] == "Activision"]
print(activision_df)
name release_date \ 64 Vampire: The Masquerade - Bloodlines 2007-03-22 65 GUN™ 2006-10-13 66 Call of Duty® 2006-10-13 68 Call of Duty: United Offensive 2006-10-13 214 Geometry Wars: Retro Evolved 2007-06-18 251 Call of Duty: World at War 2008-11-18 252 King's Quest™ Collection 2009-07-23 253 Space Quest™ Collection 2009-07-23 254 Aces of the Galaxy™ 2009-07-23 255 TimeShift™ 2009-07-23 256 3D Ultra™ Minigolf Adventures 2009-07-23 257 Prototype™ 2009-06-12 800 Singularity™ 2010-06-30 801 Call of Duty®: Black Ops 2010-11-08 1163 Prototype 2 2012-07-26 1213 Call of Duty®: Black Ops II 2012-11-12 1335 Call of Duty®: Ghosts 2014-03-25 1346 Call of Duty®: Advanced Warfare - Gold Edition 2014-11-03 2991 Call of Duty®: Infinite Warfare 2016-11-03 6485 Call of Duty®: Modern Warfare® Remastered 2017-07-27 9248 Call of Duty®: WWII 2017-11-02 9709 Police Quest™ Collection 2016-08-29 9743 Gabriel Knight: Sins of the Father® 2016-08-29 9806 The Beast Within: A Gabriel Knight® Mystery 2016-08-29 9835 Gabriel Knight® 3: Blood of the Sacred, Blood ... 2016-08-29 9960 Arcanum: Of Steamworks and Magick Obscura 2016-08-29 10003 Phantasmagoria 2: A Puzzle of Flesh 2016-08-29 10004 Phantasmagoria 2016-08-29 10042 Quest for Glory 1-5 2016-08-29 10636 Caesar™ 3 2016-08-29 10637 Caesar™ IV 2016-08-29 12147 Vampire: The Masquerade - Redemption 2017-04-18 12171 Police Quest: SWAT 2016-12-15 12172 SWAT 3: Tactical Game of the Year Edition 2017-04-18 12315 Pharaoh + Cleopatra 2016-12-15 12325 Return to Krondor 2016-12-15 12353 Zeus + Poseidon 2016-12-15 12485 Spycraft: The Great Game 2017-04-18 12528 Zork Anthology 2017-04-18 12531 Zork: Grand Inquisitor 2017-04-18 12548 Zork Nemesis: The Forbidden Lands 2017-04-18 12574 Call to Power II 2017-04-18 13047 Return to Zork 2017-04-18 17961 Crash Bandicoot™ N. Sane Trilogy 2018-06-29 developer publisher \ 64 Troika Games Activision 65 Neversoft Activision 66 Infinity Ward Activision 68 Gray Matter Studios Activision 214 Bizarre Creations Activision 251 Treyarch Activision 252 Sierra Activision 253 Sierra Activision 254 Artech Studios Activision 255 Saber Interactive Activision 256 Wanako Games Activision 257 Radical Entertainment Activision 800 Raven Software Activision 801 Treyarch Activision 1163 Radical Entertainment Activision 1213 Treyarch Activision 1335 Infinity Ward Activision 1346 Sledgehammer Games;Raven Software Activision 2991 Infinity Ward Activision 6485 Raven Software;Beenox Activision 9248 Sledgehammer Games;Raven Software Activision 9709 Sierra Activision 9743 Sierra On-Line Activision 9806 Sierra On-Line Activision 9835 Sierra On-Line Activision 9960 Troika Games Activision 10003 Sierra Activision 10004 Sierra Activision 10042 Sierra Activision 10636 Impressions Games Activision 10637 Tilted Mill Entertainment, Inc. Activision 12147 Nihilistic Software Activision 12171 Yosemite Entertainment Activision 12172 Sierra Activision 12315 Impressions Games Activision 12325 PyroTechnix Activision 12353 Impressions Games Activision 12485 Activision Activision 12528 Infocom Activision 12531 Activision Activision 12548 Zombie Studios Activision 12574 Activision Activision 13047 Activision Activision 17961 Vicarious Visions;Iron Galaxy Activision genres positive_ratings negative_ratings price 64 Action 6161 362 14.99 65 Action 740 87 9.99 66 Action 1555 117 14.99 68 Action 490 97 14.99 214 Casual 583 62 2.99 251 Action 19595 1483 19.99 252 Adventure 125 32 14.99 253 Adventure 143 42 9.99 254 Action;Casual 14 16 6.99 255 Action 623 159 9.99 256 Sports 50 28 6.99 257 Action;Adventure 3702 904 14.99 800 Action 2766 227 14.99 801 Action 14201 1839 29.99 1163 Action;Adventure 5411 2244 19.99 1213 Action 25827 4658 39.99 1335 Action 14892 10757 39.99 1346 Action 13389 8379 39.99 2991 Action;Adventure 7821 10570 39.99 6485 Violent;Action 1148 1112 34.99 9248 Action 10753 8288 44.99 9709 Adventure 32 15 7.99 9743 Adventure 41 8 4.99 9806 Adventure 50 6 4.99 9835 Adventure 15 16 4.99 9960 RPG 522 76 4.99 10003 Adventure 60 16 4.99 10004 Adventure 127 22 7.99 10042 Adventure 141 11 7.99 10636 Simulation;Strategy 315 50 4.99 10637 Simulation;Strategy 115 96 7.99 12147 Violent;RPG 165 30 4.79 12171 Action;Simulation;Strategy 11 12 4.79 12172 Violent;Action;Simulation 71 53 6.99 12315 Simulation;Strategy 399 75 6.99 12325 RPG 11 14 4.79 12353 Strategy 274 27 6.99 12485 Adventure 6 1 4.79 12528 Adventure 10 3 4.79 12531 Adventure 14 0 4.79 12548 Nudity;Violent;Adventure 8 2 4.79 12574 Strategy 10 14 4.79 13047 Adventure 11 0 4.79 17961 Action 3555 237 34.99
num_rows = activision_df.shape[0]
#Checking, how many games are from Activision
print(f'The dataset contains {num_rows} rows.')
The dataset contains 44 rows.
import math
import matplotlib.pyplot as plt
def GetRating(positiveVotes, negativeVotes):
totalVotes = positiveVotes + negativeVotes
average = positiveVotes / totalVotes
score = average - (average - 0.5) * 2 ** -math.log10(totalVotes + 1)
return score * 100
# Calculate the rating column using apply()
activision_df['Rating'] = activision_df.apply(lambda row: GetRating(row['positive_ratings'], row['negative_ratings']), axis=1)
# Reset the index
activision_df = activision_df.reset_index(drop=True)
# Set the figure size and DPI
plt.figure(figsize=(10, 6), dpi=100)
# Plot the ratings with custom styling options
plt.bar(activision_df.index, activision_df['Rating'], color='skyblue', edgecolor='black')
# Add labels and title
plt.ylabel('Rating')
plt.title('Game Ratings')
# Set the y-axis limits from 0 to 100
plt.ylim(0, 100)
# Add grid lines
plt.grid(axis='y', linestyle='--')
# Customize tick labels
plt.xticks(fontsize=8)
plt.yticks(fontsize=8)
# Remove the top and right spines
plt.gca().spines['top'].set_visible(False)
plt.gca().spines['right'].set_visible(False)
# Show the plot
plt.show()
C:\Users\tuvsh\AppData\Local\Temp/ipykernel_17184/2189189376.py:11: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy activision_df['Rating'] = activision_df.apply(lambda row: GetRating(row['positive_ratings'], row['negative_ratings']), axis=1)
#top 3 rated games from activision
activision_df = activision_df.sort_values("Rating", ascending=False)
ATVI_top3 = activision_df.head(3)
ATVI_top3
name | release_date | developer | publisher | genres | positive_ratings | negative_ratings | price | Rating | |
---|---|---|---|---|---|---|---|---|---|
0 | Vampire: The Masquerade - Bloodlines | 2007-03-22 | Troika Games | Activision | Action | 6161 | 362 | 14.99 | 91.291094 |
5 | Call of Duty: World at War | 2008-11-18 | Treyarch | Activision | Action | 19595 | 1483 | 19.99 | 90.818877 |
43 | Crash Bandicootâ„¢ N. Sane Trilogy | 2018-06-29 | Vicarious Visions;Iron Galaxy | Activision | Action | 3555 | 237 | 34.99 | 90.089024 |
import pandas as pd
url = 'https://raw.githubusercontent.com/TuvshinSelenge/Activision_Stock_Price_Analysis/main/act_bliz.csv'
df_stock = pd.read_csv(url)
df_stock = df_stock.drop(["Open","High","Low","Volume","Currency"], axis=1)
df_stock.head(5)
Date | Close | |
---|---|---|
0 | 2010-01-04 | 11.30 |
1 | 2010-01-05 | 11.32 |
2 | 2010-01-06 | 11.26 |
3 | 2010-01-07 | 10.99 |
4 | 2010-01-08 | 10.90 |
%pip install yfinance
import yfinance as yf
stock_symbol = "ATVI"
start_date = "2006-01-01"
end_date = "2009-12-31"
data = yf.download(stock_symbol, start=start_date, end=end_date)
settlement_prices = data["Close"]
settlement_prices = data["Close"].to_frame().reset_index()
print(settlement_prices)
[notice] A new release of pip available: 22.2.2 -> 23.1.2 [notice] To update, run: C:\Users\tuvsh\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\python.exe -m pip install --upgrade pip
Requirement already satisfied: yfinance in c:\users\tuvsh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (0.2.18) Requirement already satisfied: requests>=2.26 in c:\users\tuvsh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from yfinance) (2.30.0) Requirement already satisfied: cryptography>=3.3.2 in c:\users\tuvsh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from yfinance) (40.0.2) Requirement already satisfied: beautifulsoup4>=4.11.1 in c:\users\tuvsh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from yfinance) (4.12.2) Requirement already satisfied: numpy>=1.16.5 in c:\users\tuvsh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from yfinance) (1.21.1) Requirement already satisfied: html5lib>=1.1 in c:\users\tuvsh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from yfinance) (1.1) Requirement already satisfied: pandas>=1.3.0 in c:\users\tuvsh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from yfinance) (1.5.0) Requirement already satisfied: lxml>=4.9.1 in c:\users\tuvsh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from yfinance) (4.9.2) Requirement already satisfied: multitasking>=0.0.7 in c:\users\tuvsh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from yfinance) (0.0.11) Requirement already satisfied: pytz>=2022.5 in c:\users\tuvsh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from yfinance) (2023.3) Requirement already satisfied: appdirs>=1.4.4 in c:\users\tuvsh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from yfinance) (1.4.4) Requirement already satisfied: frozendict>=2.3.4 in c:\users\tuvsh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from yfinance) (2.3.8) Requirement already satisfied: soupsieve>1.2 in c:\users\tuvsh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from beautifulsoup4>=4.11.1->yfinance) (2.2.1) Requirement already satisfied: cffi>=1.12 in c:\users\tuvsh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from cryptography>=3.3.2->yfinance) (1.14.6) Requirement already satisfied: six>=1.9 in c:\users\tuvsh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from html5lib>=1.1->yfinance) (1.16.0) Requirement already satisfied: webencodings in c:\users\tuvsh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from html5lib>=1.1->yfinance) (0.5.1) Requirement already satisfied: python-dateutil>=2.8.1 in c:\users\tuvsh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from pandas>=1.3.0->yfinance) (2.8.1) Requirement already satisfied: urllib3<3,>=1.21.1 in c:\users\tuvsh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from requests>=2.26->yfinance) (1.26.6) Requirement already satisfied: charset-normalizer<4,>=2 in c:\users\tuvsh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from requests>=2.26->yfinance) (3.1.0) Requirement already satisfied: idna<4,>=2.5 in c:\users\tuvsh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from requests>=2.26->yfinance) (2.10) Requirement already satisfied: certifi>=2017.4.17 in c:\users\tuvsh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from requests>=2.26->yfinance) (2021.5.30) Requirement already satisfied: pycparser in c:\users\tuvsh\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from cffi>=1.12->cryptography>=3.3.2->yfinance) (2.20) Note: you may need to restart the kernel to use updated packages. [*********************100%***********************] 1 of 1 completed Date Close 0 2006-01-03 6.970 1 2006-01-04 7.055 2 2006-01-05 7.115 3 2006-01-06 7.445 4 2006-01-09 7.375 ... ... ... 1001 2009-12-23 11.360 1002 2009-12-24 11.440 1003 2009-12-28 11.380 1004 2009-12-29 11.290 1005 2009-12-30 11.390 [1006 rows x 2 columns]
stock_df = pd.concat([settlement_prices, df_stock])
stock_df["Date"] = pd.to_datetime(stock_df["Date"]) # Convert "Date" column to Timestamp
stock_df = stock_df.sort_values(by="Date").reset_index(drop=True)
stock_df = stock_df.rename(columns={"Close": "Settlement Price"})
stock_df
Date | Settlement Price | |
---|---|---|
0 | 2006-01-03 | 6.970 |
1 | 2006-01-04 | 7.055 |
2 | 2006-01-05 | 7.115 |
3 | 2006-01-06 | 7.445 |
4 | 2006-01-09 | 7.375 |
... | ... | ... |
4192 | 2022-08-29 | 78.750 |
4193 | 2022-08-30 | 78.620 |
4194 | 2022-08-31 | 78.490 |
4195 | 2022-09-01 | 78.550 |
4196 | 2022-09-02 | 77.530 |
4197 rows × 2 columns
import matplotlib.pyplot as plt
# Set the figure size and DPI
plt.figure(figsize=(10, 6), dpi=100)
# Get the unique release dates from ATVI_top3
release_dates = ATVI_top3["release_date"].unique()
# Plot the price development from stock_df
plt.plot(stock_df["Date"], stock_df["Settlement Price"], label="Price Development")
# Plot the price development for each release date
for release_date in release_dates:
# Filter stock_df for the specific release date
specific_prices = stock_df[stock_df["Date"] == release_date]
# Plot the specific prices with markers
plt.plot(specific_prices["Date"], specific_prices["Settlement Price"], 'ro', label=f"Release Date: {release_date}")
# Add labels and title to the plot
plt.xlabel("Date")
plt.ylabel("Price")
plt.title("Price Development with Release Dates")
plt.legend()
# Show the plot
plt.show()
import matplotlib.dates as mdates
from datetime import datetime, timedelta
# Convert the release_date column to datetime type
ATVI_top3["release_date"] = pd.to_datetime(ATVI_top3["release_date"], errors='coerce')
# Remove rows with invalid release dates
ATVI_top3 = ATVI_top3.dropna(subset=["release_date"])
# Set the figure size and DPI
plt.figure(figsize=(14, 18), dpi=100) # Adjust the figure size as needed
# Get the unique release dates and game names from ATVI_top3
release_dates = ATVI_top3["release_date"].unique()
game_names = ATVI_top3["name"].unique()
# Define the 2-week timeframe
timeframe = np.timedelta64(14, 'D')
# Calculate the number of rows and columns for subplots
num_plots = len(release_dates)
num_cols = 1
num_rows = num_plots // num_cols
# Create subplots with appropriate spacing
fig, axs = plt.subplots(num_rows, num_cols, figsize=(14, num_plots*5), dpi=100)
plt.subplots_adjust(hspace=0.5)
# Plot the price development for each release date
for i, release_date in enumerate(release_dates):
# Get the start and end dates for the 2-week timeframe
start_date = release_date - timeframe
end_date = release_date + timeframe
# Filter stock_df within the 2-week timeframe
prices_within_timeframe = stock_df[(stock_df["Date"] >= start_date) & (stock_df["Date"] <= end_date)]
# Select the appropriate subplot
if num_plots > 1:
ax = axs[i]
else:
ax = axs
# Plot the price development within the 2-week timeframe
ax.plot(prices_within_timeframe["Date"], prices_within_timeframe["Settlement Price"], label="Stock Price")
# Add a red line to mark the release date
ax.axvline(x=release_date, color='red', linestyle='--')
# Add parallel lines for better visual clarity
min_price = prices_within_timeframe["Settlement Price"].min()
max_price = prices_within_timeframe["Settlement Price"].max()
price_range = max_price - min_price
line1 = min_price + 0.25 * price_range
line2 = min_price + 0.5 * price_range
line3 = min_price + 0.75 * price_range
ax.axhline(y=line1, color='lightgray', linestyle='--', linewidth=0.5)
ax.axhline(y=line2, color='lightgray', linestyle='--', linewidth=0.5)
ax.axhline(y=line3, color='lightgray', linestyle='--', linewidth=0.5)
# Get the game name for the current release date
game_name = ATVI_top3.loc[ATVI_top3["release_date"] == release_date, "name"].values[0]
# Add the game name as a legend
ax.legend(["Stock Price", game_name])
# Convert release_date to numpy.datetime64 object
release_date = np.datetime64(release_date)
# Format the title with the release date in yy/mm/dd format
formatted_date = np.datetime_as_string(release_date, unit='D')
ax.set_title(f"Price Development within 2-Week Timeframe for Release Date: {formatted_date}")
# Set the x-axis tick locator and formatter
# Set the x-axis tick locator and formatter
ax.xaxis.set_major_locator(mdates.AutoDateLocator(maxticks=10))
ax.xaxis.set_major_formatter(mdates.DateFormatter("%y/%m/%d"))
# Display the plots
plt.tight_layout()
plt.show()
C:\Users\tuvsh\AppData\Local\Temp/ipykernel_17184/576415073.py:5: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy ATVI_top3["release_date"] = pd.to_datetime(ATVI_top3["release_date"], errors='coerce')
<Figure size 1400x1800 with 0 Axes>