AI/ML model
AI model for analyzing historical stock prices
import requests
import tqdm
from FiinQuantX import FiinSession
from bs4 import BeautifulSoup
import google.generativeai as genai
import re
import numpy as np
import pandas as pd
import os
GOOGLE_GEMINI_API_KEY = os.getenv('GOOGLE_GEMINI_API_KEY')
genai.configure(api_key=GOOGLE_GEMINI_API_KEY)
model = genai.GenerativeModel("gemini-1.5-flash")
client = FiinSession('USERNAME', 'PASSWORD').login()
VCB_data = client.Fetch_Trading_Data(
tickers=['VCB'],
fields=['close'],
realtime=False,
adjusted=True,
by='1d',
from_date='2020-01-01',
to_date='2025-01-29').get_data()Output:
Machine learning model for stock price prediction
Retrieve stock data from the FiinQuant library
1. Linear Regression
Prepare and run the model

2. Random Forest/ XG Boost

3. Long short-term memory network (LSTM)
For an LSTM network to effectively learn stock price characteristics, it needs additional features beyond open, high, low, and volume.
Create a "Label" column, which is the 'Close' price of the previous day.
Tạo thêm feature
Standardize data
Model
.....

Last updated