# Finance: Learning how to use stockstats, python ver. 2

Last Updated on August 24, 2022 by shibatau

## I. What shall we learn?

I’m begin to learn finance and how to use Python for it again. In this post, we will learn how to use stockstats from the turorial:

Stockstats — a handy, stocks-oriented pandas DataFrame wrapper

## II. Getting change, rate, close_-1_d and log-ret

Here are simple explanations about change, rate, close_-1_d and log-ret quoted from the link above.

change / rate — these are the simple returns, that is the daily percentage change between the stock prices. Values are expressed in percentages.
close_-1_d — this is the price difference between time t and t-1. We will get back later to this special way of requesting values is stockstats.
log-ret — the log returns.

You can get these values very easily with stockstas. Let’s take Toyota Motor Corporation (TM) as an example.

### 1.Getting data

import yfinance as yf
df = yf.download("TM", start="2021-01-01", end="2022-08-20)

### 2.Convert Pandas DataFrame to StockDataFrame

stock_df = StckDataFrame.retype(df) 

### 3.Calculating changes, rates, close_-1_days and log returns.

stock_df[["change", "rate", "close_-1_d", "log-ret"]]

Now you will get the following table:

### 4.Creating a multiple line charts

# creating a multiple line chart
stock_df[["close", "close_10_sma", "close_50_sma"]].plot(title="Toyota Motor Corporationd")

You can learn about SMA from my post:

Simple Moving Average

I have also created the chart with Pandas and Plotly Express.

You can see the scripts here: