EXAMPLE OF MARKOV CHAIN with python
Project: Use Python combined with open-source AI in a decision-making process
The idea for my project started after our Singapour Module. I returned to Paris, where I live
with my wife and two young daughters. After March, the weather improved, and I considered
buying a car to leave the city for weekends and vacations. In the meantime, I noticed that
many companies and start-ups propose rental cars in Paris.
I wondered if it was the best option.
I noticed that each company and each offer by the same company has a different approach to
pricing. Some have a monthly fee; others don't; some include fuel in the price per km, others
don't; Some give a discount after a certain nb of rentals etc.
I tried to do a rough calculation to make my choice and shortly understood that it was too
complicated.
I tried to ask a popular AI to help me, but they failed to consider all variables.
Consequently, I thought about using what I learned in Python to help me compare all services
available. It was my first coding experience, and I was excited to have an opportunity to be
involved in a problem-solving situation.
Data Collection:
I looked for my track record for rental cars and extracted the following data in an Excel file
Excel file: CarRental_Paris
Sheet: Consumption
Month Nb of rentals Nb of Days Nb of km
1 1 1 50
2 1 2 500
3 1 3 600
4 2 5 1200
5 2 2 100
6 2 7 1850
7 2 6 900
8 1 20 3500
9 2 4 500
10 1 2 80
11 1 1 30
12 0 0 0
Then I looked for prices online and deducted average costs for 10 options, including buying a
car.
I identified the following variables:
Nb_of_Rentals: Nb of times that a rental happens per month a given customer
Nb_days_per_month: Total Nb of days of a rental per month a given customer
Nb_Km: Total Nb of days of a rental per month a given customer
Monthly_Fee
Tarif_J1:Price for the first rental day
Tarif_JX: Price for the following rental days
Limit_Free_Km: Nb of km before change in tarification
Tarif_before_limit
Tarif_after_limit
Excel file: CarRental_Paris
Sheet: Tarifs
Service Monthly Tarif Tarif Free Price per km before Price per Km after Delive
Name fee J1 JX Kms limit limit ry
Getaround 0 93 93 200 0,102 0,262 NO
CC liberté 0 37,5 27,5 50 0 0,29 NO
CC
Economique 3 27,5 27,5 50 0,47 0,29 NO
CC plus 9 23,5 23,5 50 0,42 0,29 NO
CC Extra 18 19,5 19,5 50 0,32 0,29 NO
Acquisition 518 0 0 0 0,102 0,102 YES
Ubeeqo 0 72 50 30 0,102 0,302 NO
Hertz 0 150 150 0 0,102 0,102 NO
Virtuo 0 100 100 100 0,102 0,302 YES
Carlili 0 137 137 200 0,102 0,452 YES
Assumptions:
I consider :
• a client who is not a car fan but wants to drive his family safely.
• a medium-range car for families type Peugot 2008 or Duster
Parkin cost in Paris : 250 € per month
Insurance cost: 150 € per month
The average consumption of fuel is 0,06 L/km
The average price for fuel is 1,7€ per liter
Coding:
Using what we learned in the Python class with Loops, functions, and plotting technics, I
built a basic code to:
• Compare different services for my consumption by showing diagrams
• Comparing each service on a monthly
• Comparing each service on a monthly
Code attached "Compare rental Services for Charles".
To complement this analysis, I added a value proposal map to include my experience with
these services in the process.
NB: the diagonal did not get printed on the picture as expected.
Other profile
To be able to challenge different scenarios
In addition, I modified and built a simplified code to make it easily available for anyone with
the same question. Python will only ask for
1) The average number of rental days per month and
2) The average number of kilometers per month
3) Below is the result for someone who drives 1000 Km per month for 6 days of rental
See the code attached.
Conclusion
Acquisition is not the cheapest solution, but it offers significant advantages, around 1000 km
per month.
However, it is the solution with the higher switching cost.
Considering the month-to-month analysis, Caumunauto seems to be the best value-to-price
option. I could always consider other options, such as Carlili or Hertz if I need specific
services that CC won't offer, such as Delivery or returning the car to a different station.
Appendix 1: Compare rental Services for Charles
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Read the Excel files
df = pd.read_excel(r'C:\Users\charl\OneDrive\Documents\INSEAD\CarRental_Paris.xlsx', sheet_name='Tarifs')
df2 = pd.read_excel(r'C:\Users\charl\OneDrive\Documents\INSEAD\CarRental_Paris.xlsx',
sheet_name='Consumption', header=None)
RentalCarServices = np.array(df)
Consuption = np.array(df2)
# Function to calculate the monthly cost for a given service
def Calculate_Monthly_Cost(service, Nb_of_Rentals, Nb_days_per_month, Nb_Km):
Monthly_Fee, Tarif_J1, Tarif_JX, Limit_Free_Km, Tarif_before_limit, Tarif_after_limit, _ = service[1:]
# Calculate the cost for the daily fee
if Nb_days_per_month == 0:
Cost_J1 = 0
else:
Cost_J1 = Tarif_J1 * Nb_of_Rentals
Cost_JX = (Nb_days_per_month - Nb_of_Rentals) * Tarif_JX
# Calculate the cost for the kilometer fee
if Nb_Km <= Limit_Free_Km:
Cost_Km = Tarif_before_limit * Nb_Km
else:
Cost_Km = Limit_Free_Km * Tarif_before_limit + (Nb_Km - Limit_Free_Km) * Tarif_after_limit
Monthly_Cost = Monthly_Fee + Cost_J1 + Cost_JX + Cost_Km
return Monthly_Cost
# Function to calculate the yearly cost for a given service
def Calculate_Yearly_Cost(service):
Array_Monthly_Cost = np.array([])
Yearly_Cost = 0
for i in range(1, 13):
Nb_of_Rentals = Consuption[i, 1]
Nb_days_per_month = Consuption[i, 2]
Nb_Km = Consuption[i, 3]
Monthly_Cost = Calculate_Monthly_Cost(service, Nb_of_Rentals, Nb_days_per_month, Nb_Km)
Array_Monthly_Cost = np.append(Array_Monthly_Cost, Monthly_Cost)
Yearly_Cost += Monthly_Cost
return Yearly_Cost, Array_Monthly_Cost
# List of services (name, Monthly_Fee, Tarif_J1, Tarif_JX, Limit_Free_Km, Tarif_before_limit, Tarif_after_limit,
Delivery)
services = RentalCarServices[:10]
# Calculate the yearly cost for each service
yearly_costs = []
for service in services:
yearly_cost, _ = Calculate_Yearly_Cost(service)
yearly_costs.append(yearly_cost)
# Plotting yearly costs for each service
plt.figure(figsize=(10, 6))
for i, cost in enumerate(yearly_costs):
delivery = services[i][-1]
linestyle = 'dotted' if delivery == 'YES' else 'solid'
plt.bar(i, cost, label=services[i, 0], linestyle=linestyle, edgecolor='black', hatch='/' if delivery == 'YES' else '')
plt.xticks(range(len(services)), services[:, 0], rotation=45)
plt.xlabel('Service')
plt.ylabel('Yearly Cost')
plt.title('Yearly Cost for Each Service')
plt.legend()
plt.show()
# Calculate the monthly costs for each service
monthly_costs_list = []
for service in services:
_, monthly_costs = Calculate_Yearly_Cost(service)
monthly_costs_list.append(monthly_costs)
# Plotting monthly costs for each service
plt.figure(figsize=(10, 6))
for i, monthly_costs in enumerate(monthly_costs_list):
delivery = services[i][-1]
linestyle = 'dotted' if delivery == 'YES' else 'solid'
plt.plot(range(1, 13), monthly_costs, label=services[i, 0], linestyle=linestyle)
plt.xlabel('Month')
plt.ylabel('Monthly Cost')
plt.title('Monthly Cost for Each Service')
plt.legend()
plt.show()
Appendix 2: Compare rental Services for others
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Read the Excel file for rental car services
df = pd.read_excel(r'C:\Users\charl\OneDrive\Documents\INSEAD\CarRental_Paris.xlsx', sheet_name='Tarifs')
RentalCarServices = np.array(df)
# Function to calculate the monthly cost for a given service
def Calculate_Monthly_Cost(service, avg_rental_days, avg_km_per_month):
Monthly_Fee, Tarif_J1, Tarif_JX, Limit_Free_Km, Tarif_before_limit, Tarif_after_limit = service[1:-1]
# Calculate the cost for the daily fee
Cost_J1 = Tarif_J1 * avg_rental_days
Cost_JX = (30 - avg_rental_days) * Tarif_JX
# Calculate the cost for the kilometer fee
if avg_km_per_month <= Limit_Free_Km:
Cost_Km = Tarif_before_limit * avg_km_per_month
else:
Cost_Km = Limit_Free_Km * Tarif_before_limit + (avg_km_per_month - Limit_Free_Km) * Tarif_after_limit
Monthly_Cost = Monthly_Fee + Cost_J1 + Cost_JX + Cost_Km
return Monthly_Cost
# Function to calculate the yearly cost for a given service
def Calculate_Yearly_Cost(service, avg_rental_days, avg_km_per_month):
Array_Monthly_Cost = np.array([])
Yearly_Cost = 0
for i in range(1, 13):
Monthly_Cost = Calculate_Monthly_Cost(service, avg_rental_days, avg_km_per_month)
Array_Monthly_Cost = np.append(Array_Monthly_Cost, Monthly_Cost)
Yearly_Cost += Monthly_Cost
return Yearly_Cost, Array_Monthly_Cost
# List of services (name, Monthly_Fee, Tarif_J1, Tarif_JX, Limit_Free_Km, Tarif_before_limit, Tarif_after_limit,
Delivery)
services = RentalCarServices[:10]
# User input for average rental days and average kilometers driven per month
avg_rental_days = int(input("Enter your average number of rental days per month: "))
avg_km_per_month = int(input("Enter your average number of kilometers driven with a rental car per month: "))
# Calculate the yearly cost for each service based on user input
yearly_costs = []
for service in services:
yearly_cost, _ = Calculate_Yearly_Cost(service, avg_rental_days, avg_km_per_month)
yearly_costs.append(yearly_cost)
# Plotting yearly costs for each service
plt.figure(figsize=(10, 6))
plt.bar(range(len(services)), yearly_costs)
plt.xticks(range(len(services)), services[:, 0], rotation=45)
plt.xlabel('Service')
plt.ylabel('Yearly Cost')
plt.title('Yearly Cost for Each Service')
plt.show()