Sdds004a Ai Journal
Sdds004a Ai Journal
Sdds004a Ai Journal
ARTIFICIAL INTELLIGENCE
SUBMITTED BY
SYDS
Rollno SDDS050A
SEMESTER III
ACADEMIC YEAR
2023 - 2024
CERTIFICATE
This is to certify that Mr. Kash Sharma of Second year B.SC.DS Div.:
A, Roll No. SDDS050A of Semester III (2023 - 2024) has successfully
completed the Journal for the Major course ARTIFICIAL
INTELLIGENCE as per the guidelines of KES’ Shroff College of Arts
and Commerce, Kandivali(W), Mumbai-400067.
DFS algorithm
2. Take the top item of the stack and add it to the visited list.
3. Create a list of that vertex's adjacent nodes. Add the ones which aren't in the visited list to
the top of the stack.
4. Keep repeating steps 2 and 3 until the stack is empty.
Example
We use an undirected graph with 5 vertices. We start from vertex 0, the DFS algorithm starts
by putting it in the Visited list and putting all its adjacent vertices in the stack. Next, we visit
the element at the top of stack i.e. 1 and go to its adjacent nodes. Since 0 has already been
visited, we visit 2 instead. Vertex 2 has an unvisited adjacent vertex in 4, so we add that to the
top of the stack and visit it. After we visit the last element 3, it doesn't have any unvisited
adjacent nodes, so we have completed the Depth First Traversal of the graph.
Program
BFS algorithm
1. Start by putting any one of the graph's vertices at the back of a queue.
2. Take the front item of the queue and add it to the visited list.
3. Create a list of that vertex's adjacent nodes. Add the ones which aren't in the visited list to
the back of the queue.
4. Keep repeating steps 2 and 3 until the queue is empty.
Example
Let's see how the Breadth First Search algorithm works with an example. We use an
undirected graph with 5 vertices. We start from vertex 0, the BFS algorithm starts by putting
it in the Visited list and putting all its adjacent vertices in the stack .Next, we visit the element
at the front of queue i.e. 1 and go to its adjacent nodes. Since 0 has already been visited, we
visit 2 instead. Vertex 2 has an unvisited adjacent vertex in 4, so we add that to the back of the
queue and visit 3, which is at the front of the queue. Only 4 remains in the queue since the
only adjacent node of 3 i.e. 0 is already visited. We visit it. Since the queue is empty, we have
completed the Breadth First Traversal of the graph.
Program:
Aim : Implementation of A*
Objective: students will able to learn use of A* algorithm of AI
A * algorithm
Create a priority queue (open list) and add the starting point 'S' to it with a cost of 0.Create a
closed list to keep track of visited nodes.While the open list is not empty:
a. Pop the node with the lowest cost (including both the cost to reach the node and the estimated
cost to reach the goal) from the open list. Let's call this node 'current'.
b. If 'current' is the goal node 'G', you have found the shortest path.
c. Otherwise, for each of the four possible neighbor nodes (up, down, left, right) of 'current':
Program:
Program :
Program :
10 | A r t i f i c i a l I n t e l l i g e n c e SDDS050
A
11 | A r t i f i c i a l I n t e l l i g e n c e SDDS050
A
(Ai Project)
Automated Trading System
Introduction
- Purpose of the Document: This document serves as a guide for users and
maintainers of the trading system. It is important for understanding and
operating the system effectively.
System Architecture
- High-level architecture diagram: Provide a visual representation of the
system's components and data flows.
- Components and their roles: Elaborate on each component, including the core
trading engine, data feed handler, risk management module, order execution
module, backtesting framework, and live trading interface.
- Data flow within the system: Describe how data moves from data sources to
trading decisions and order execution.
- Dependencies and libraries: List all required libraries and packages, including
version numbers.
Getting Started
12 | A r t i f i c i a l I n t e l l i g e n c e SDDS050
A
- Running the system for the first time: Offer clear instructions for starting the
system.
- Basic usage instructions: Detail how to load a trading strategy, monitor system
status, execute backtests, and initiate live trading.
Strategy Description
- Explanation of the trading strategy used: Describe the trading methodology,
including technical and fundamental analysis.
- Parameters and indicators used: List and explain key strategy parameters and
indicators.
- Risk management techniques: Explain how the system manages risk, including
stop-loss levels and position sizing.
Data Sources
- Description of data sources: List and provide details about the data providers
or exchanges used.
- How to connect and fetch data: Explain how to configure data connections and
fetch historical and real-time data.
Trading Execution
- Details of order types: Explain the types of orders supported, such as market,
limit, and stop-limit.
- How orders are placed and executed: Describe the order submission process
and execution logic.
- Handling order cancellations and errors: Provide guidance on how the system
deals with order cancellations and errors.
Backtesting
- How to conduct backtests: Explain how to set up and run backtests on
historical data.
13 | A r t i f i c i a l I n t e l l i g e n c e SDDS050
A
- Interpretation of backtest results: Detail how to analyze backtest results,
including profit and loss, drawdown, and other performance metrics.
Live Trading
- Setting up live trading accounts: Explain how to connect the system to live
brokerage accounts.
- Monitoring and controlling live trading: Describe how to monitor live trading,
intervene when necessary, and shut down the system safely.
- Error handling and recovery: Provide procedures for handling errors during
live trading, including connectivity issues and order execution problems.
Risk Management
- Risk assessment and mitigation strategies: Elaborate on how the system
assesses and mitigates risks, including setting risk tolerance levels.
- Position sizing and portfolio management: Explain how the system determines
position sizes and manages the overall portfolio.
- Logging system events and errors: Describe what events are logged and how to
access and interpret log files.
- Compliance with trading regulations: Detail how the system complies with
legal and regulatory requirements.
- User authentication and authorization: Explain user access levels and how to
manage user permissions.
14 | A r t i f i c i a l I n t e l l i g e n c e SDDS050
A
- Routine maintenance tasks: List regular maintenance activities, such as data
updates and software updates.
- Debugging and testing procedures: Explain how to debug and test trading
strategies and system components.
- Adding new data sources or indicators: Explain how to integrate new data
sources and indicators into the system.
FAQs
- Answers to frequently asked questions: Include concise answers to common
questions and issues that users might encounter.
- Common issues and their solutions: List known issues and their resolutions
with detailed steps.
Appendices
- Glossary of terms: Define and explain trading-related terms and jargon.
15 | A r t i f i c i a l I n t e l l i g e n c e SDDS050
A
- References and further reading: List books, articles, and online resources for
users who want to learn more.
Change Log
- Record of changes and updates to the system: Maintain a version history with
dates, descriptions of changes, and contributors.
Source code:
import random
class MockTradingSystem:
self.balance = starting_balance
if action == 'buy':
self.balance -= cost
else:
16 | A r t i f i c i a l I n t e l l i g e n c e SDDS050
A
elif action == 'sell':
self.balance += revenue
else:
# Example usage:
if __name__ == "__main__":
trading_system = MockTradingSystem()
trading_system.execute_trade('GOOGL', 5, 'buy')
trading_system.execute_trade('AAPL', 8, 'sell')
Explaination:
17 | A r t i f i c i a l I n t e l l i g e n c e SDDS050
A
Certainly! Here's an explanation of the provided Python code for a simplified mock trading system:
```python
import random
```
- This line imports the `random` module, which is used to generate random numbers. In this code, it's
used to simulate stock prices and trading actions.
```python
class MockTradingSystem:
self.balance = starting_balance
```
- This code defines a Python class called `MockTradingSystem`. It has an `__init__` method that initializes
the trading system with a starting balance (default is $10,000).
```python
if action == 'buy':
self.balance -= cost
else:
self.balance += revenue
18 | A r t i f i c i a l I n t e l l i g e n c e SDDS050
A
print(f"Sold {quantity} shares of {symbol} for ${revenue}.")
else:
```
- This method, `execute_trade`, is used to simulate buying and selling stocks. It takes three arguments:
`symbol` (the stock symbol), `quantity` (the number of shares to buy or sell), and `action` (either 'buy' or
'sell').
- If the `action` is 'buy', it calculates the cost using the `calculate_cost` method and checks if there's
enough balance to make the purchase. If there is, it deducts the cost from the balance and prints a
message indicating the purchase. If there isn't enough balance, it prints an "Insufficient balance"
message.
- If the `action` is 'sell', it calculates the revenue using the `calculate_revenue` method, adds the revenue
to the balance, and prints a message indicating the sale.
- If the `action` is neither 'buy' nor 'sell', it prints an "Invalid action" message.
```python
```
- This method, `calculate_cost`, calculates the cost of buying `quantity` shares of a stock with the given
`symbol`. In this simplified example, it generates a random cost between 1 and 100 for each share,
simulating the cost of purchasing stocks. In a real trading system, this function would retrieve the actual
stock price from a data source.
```python
```
- This method, `calculate_revenue`, calculates the revenue from selling `quantity` shares of a stock with
the given `symbol`. Like `calculate_cost`, it generates a random revenue based on a random price for
each share, simulating the revenue from selling stocks. In a real system, this function would use actual
market data.
```python
# Example usage:
if __name__ == "__main__":
trading_system = MockTradingSystem()
trading_system.execute_trade('GOOGL', 5, 'buy')
trading_system.execute_trade('AAPL', 8, 'sell')
```
Finally, this part of the code demonstrates how to use the `MockTradingSystem`. It creates an
instance of the class, `trading_system`, with the default starting balance of $10,000.
It then executes several mock trades using the `execute_trade` method, simulating buying and
selling shares of different stocks.
Note that this code is a simplified example and does not interact with real financial markets. In
a real-world trading system, you would replace the mock calculations with actual market data
and implement a more sophisticated trading strategy. Additionally, real trading systems
involve significant risk management and regulatory compliance measures, which are not
addressed in this basic example.
20 | A r t i f i c i a l I n t e l l i g e n c e SDDS050
A
In this simplified example, we have a `MockTradingSystem` class that simulates buying and
selling stocks. It uses random values for cost and revenue to mimic market transactions. A real
trading system would involve connecting to real exchanges, retrieving market data, and
implementing a more sophisticated trading strategy.
Remember that real-world trading systems require thorough testing, risk management, and
compliance with financial regulations, which are complex and beyond the scope of this
simplified example. If you're serious about building a trading system for real-world use,
consider working with experienced professionals and consulting legal and financial experts.
Output:
21 | A r t i f i c i a l I n t e l l i g e n c e SDDS050
A