Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Sdds004a Ai Journal

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 21

JOURNAL

IN THE MAJOR COURSE

ARTIFICIAL INTELLIGENCE

SUBMITTED BY

MR. Kash Sharma

SYDS

Rollno SDDS050A

SEMESTER III

UNDER THE GUIDANCE OF

ASST. PROF. HIRAL SACHALA

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.

Teacher In-charge Principal


ASST. PROF. HIRAL SACHALA Dr. L Bhushan.
INDEX
Sr. Practical Practical Name Page No.
No. No.
1. 1 Implementation of DFS 4
2. 2 Implementation of BFS 5
3. 3 Implementation of A* 6, 7
4. 4 Write a program to convert text to speech in python 8
using AI library
5. 5 Write a program to convert speech to text in python 9
using AI library .
6. 6 Implementation of N Queen problem 10, 11
Practical No. 1:
Aim : Implementation of DFS
Objective: students will able to learn use of DFS algorithm of AI

DFS algorithm

1. Start by putting any one of the graph's vertices on top of a stack.

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

4|Artificial Intelligence SDDS050


A
Practical No. 2 :

Aim : Implementation of BFS


Objective: students will able to learn use of BFS algorithm of AI

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:

5|Artificial Intelligence SDDS050


A
Practical No. 3 :

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':

i. If the neighbornis an obstacle or is in the closed list, skip it.


ii. Calculate the cost to reach the neighbor from 'current'.
iii. Calculate the estimated cost to reach the goal from the neighbor using a heuristic
(e.g., Manhattan distance).
iv. If the neighbor is not in the open list or has a lower cost, update its cost and add it to
the open list. d. Add 'current' to the closed list.

Program:

6|Artificial Intelligence SDDS050


A
7|Artificial Intelligence SDDS050
A
Practical No. 4:

Aim : Write a program to convert text to speech in python using AI library

Objective: students will able to implement AI library

pyttsx3 is a text-to-speech conversion library in Python. Unlike alternative libraries, it works


offline and is compatible with both Python 2 and 3. An application invokes the pyttsx3.init()
factory function to get a reference to a pyttsx3. Engine instance. it is a very easy to use tool
which converts the entered text into speech. The pyttsx3 module supports two voices first is
female and the second is male which is provided by “sapi5” for windows. It supports three
TTS engines :

 sapi5 – SAPI5 on Windows


 nsss – NSSpeechSynthesizer on Mac OS X
 espeak – eSpeak on every other platform program
Program:

8|Artificial Intelligence SDDS050


A
Practical No. 5:

Aim : Write a program to convert speech to text in python using AI library .

Objective: Students will able to implement AI library

Speech Recognition: is an important feature in several applications used such as home


automation, artificial intelligence, etc. This article aims to provide an introduction to how to
make use of the SpeechRecognition library of Python. This is useful as it can be used on
microcontrollers such as Raspberry Pi with the help of an external microphone.

Program :

9|Artificial Intelligence SDDS050


A
Practical No. 6:

Aim : Implementation of N Queen problem

Objective: students will able to solve N Queen problem

N - Queens problem is to place n - queens in such a manner on an n x n chessboard that no queens


attack each other by being in the same row, column or diagonal.

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.

- Overview of the Automated Trading System: Briefly describe the purpose,


goals, key features, and benefits of the trading system.

 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.

 Installation and Setup


- Prerequisites: Detail specific hardware and software requirements, supported
operating systems, and Python versions.

- Installation instructions: Provide step-by-step instructions for setting up the


system on a user's machine.

- Configuration details: Explain various configuration options, including API


keys, strategy parameters, and trading preferences.

- 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.

- Sample configuration: Provide an example configuration file with comments


explaining each parameter.

 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.

- Data preprocessing (if any): Describe any data cleaning or transformation


steps applied before analysis.

 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.

- Performance metrics: Define and explain metrics such as Sharpe ratio,


maximum drawdown, and win rate.

 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.

 Notifications and Logging


- Configuring email/SMS notifications: Detail how to set up notifications for
critical events.

- Logging system events and errors: Describe what events are logged and how to
access and interpret log files.

 Security and Compliance


- Security measures in place: Explain the security protocols, encryption
methods, and access controls implemented in the system.

- 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.

 Maintenance and Troubleshooting

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.

- Troubleshooting common issues: Provide solutions to common problems,


including error codes and troubleshooting steps.

- Debugging and testing procedures: Explain how to debug and test trading
strategies and system components.

 Customization and Extensibility


- How to customize trading strategies: Offer guidelines on modifying existing
strategies or creating custom ones.

- Adding new data sources or indicators: Explain how to integrate new data
sources and indicators into the system.

- Developing plugins or modules: Provide guidance on extending the system's


functionality through custom plugins or modules.

 Integration with External Services


- Integration with brokers and exchanges: Explain the process of connecting to
different brokers and exchanges.

- Accessing third-party APIs: Provide examples of how to use third-party APIs


for additional data or functionality.

- Using external data services: Describe how to incorporate external data


services for specialized data.

 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.

- Sample code snippets: Provide code examples illustrating various aspects of


the system.

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.

 Legal and Disclaimers


- Legal notices, disclaimers, and terms of use: Include legal disclaimers and
terms of service for users of the system.

 Source code:

import random

class MockTradingSystem:

def __init__(self, starting_balance=10000):

self.balance = starting_balance

def execute_trade(self, symbol, quantity, action):

if action == 'buy':

cost = self.calculate_cost(symbol, quantity)

if cost <= self.balance:

self.balance -= cost

print(f"Bought {quantity} shares of {symbol} for ${cost}.")

else:

print("Insufficient balance to buy.")

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':

revenue = self.calculate_revenue(symbol, quantity)

self.balance += revenue

print(f"Sold {quantity} shares of {symbol} for ${revenue}.")

else:

print("Invalid action. Use 'buy' or 'sell'.")

def calculate_cost(self, symbol, quantity):

# Mock cost calculation (replace with real data)

return random.uniform(1, 100) * quantity

def calculate_revenue(self, symbol, quantity):

# Mock revenue calculation (replace with real data)

return random.uniform(1, 100) * quantity

# Example usage:

if __name__ == "__main__":

trading_system = MockTradingSystem()

# Execute some mock trades

trading_system.execute_trade('AAPL', 10, 'buy')

trading_system.execute_trade('GOOGL', 5, 'buy')

trading_system.execute_trade('AAPL', 8, 'sell')

trading_system.execute_trade('MSFT', 12, 'buy')

 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:

def __init__(self, starting_balance=10000):

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

def execute_trade(self, symbol, quantity, action):

if action == 'buy':

cost = self.calculate_cost(symbol, quantity)

if cost <= self.balance:

self.balance -= cost

print(f"Bought {quantity} shares of {symbol} for ${cost}.")

else:

print("Insufficient balance to buy.")

elif action == 'sell':

revenue = self.calculate_revenue(symbol, quantity)

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:

print("Invalid action. Use 'buy' or 'sell'.")

```

- 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

def calculate_cost(self, symbol, quantity):

# Mock cost calculation (replace with real data)

return random.uniform(1, 100) * quantity

```

- 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

def calculate_revenue(self, symbol, quantity):

# Mock revenue calculation (replace with real data)


19 | A r t i f i c i a l I n t e l l i g e n c e SDDS050
A
return random.uniform(1, 100) * quantity

```

- 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()

# Execute some mock trades

trading_system.execute_trade('AAPL', 10, 'buy')

trading_system.execute_trade('GOOGL', 5, 'buy')

trading_system.execute_trade('AAPL', 8, 'sell')

trading_system.execute_trade('MSFT', 12, 'buy')

```

 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

You might also like