# **Ogun Library**
![Ogun Library Logo](ogun_logo.png)
The Ogun Library is a versatile risk assessment tool designed to quantify risk in various domains, industries, and contexts. Whether you need to assess financial risk, credit risk, or operational risk, Ogun offers customization, modularity, and default methods to meet your specific risk assessment needs
## **Table of Contents**
- [**Ogun Library**](#ogun-library)
- [**Table of Contents**](#table-of-contents)
- [**1. Introduction**](#1-introduction)
- [**2. Getting Started**](#2-getting-started)
- [**Installation**](#installation)
- [**Quick Start**](#quick-start)
- [**3. Library Overview**](#3-library-overview)
- [**Library Structure**](#library-structure)
- [**4. Basic Usage**](#4-basic-usage)
- [**Initializing Ogun**](#initializing-ogun)
- [**Setting Data**](#setting-data)
- [**Selecting a Risk Calculation Method**](#selecting-a-risk-calculation-method)
- [**Scoring Data**](#scoring-data)
- [**Getting the Risk Rating**](#getting-the-risk-rating)
- [**5. Extending the Library**](#5-extending-the-library)
- [**Adding Custom Risk Calculation Methods**](#adding-custom-risk-calculation-methods)
- [**Creating Custom Filters**](#creating-custom-filters)
- [**Enhancing the Default Risk Calculation Method**](#enhancing-the-default-risk-calculation-method)
- [**6. Advanced Usage**](#6-advanced-usage)
- [**Handling Exceptions**](#handling-exceptions)
- [**Customizing Risk Rating Thresholds**](#customizing-risk-rating-thresholds)
- [**7. Examples**](#7-examples)
- [**Example 1: Using a Custom Risk Calculation Method**](#example-1-using-a-custom-risk-calculation-method)
- [**Example 2: Customizing Thresholds**](#example-2-customizing-thresholds)
- [**8. FAQs**](#8-faqs)
- [**9. Support**](#9-support)
- [**10. Contributing**](#10-contributing)
- [**11. License**](#11-license)
## **1. Introduction**
The Ogun Library is a versatile risk assessment tool with customization, modularity, and default methods for quantifying risk in various domains.
## **2. Getting Started**
### **Installation**
Provide instructions on how to install the library.
```bash
pip install ogun
```
### **Quick Start**
Certainly! Here's a quick example of how to use the Ogun Library for risk assessment:
Suppose you have the following data for a user:
- `account_balance`: 10
- `account_age`: 5
- `work_status`: 4
- `Salary`: 10
You want to assess the user's risk using the default risk calculation method provided by the Ogun Library.
```python
from ogun import Ogun
# Initialize Ogun
ogun = Ogun()
# Set the user's data for risk assessment
data = {
"account_balance": 10,
"account_age": 5,
"work_status": 4,
"Salary": 10,
}
# Use the default risk calculation method
result = (
ogun.data(data)
.using()
.score("account_balance", 10)
.score("account_age", 5)
.score("work_status", 4)
.score("Salary", 10)
.get()
)
# Print the risk assessment
print("Risk Rating:", result.rating)
print("Status:", result.status)
```
In this example:
1. We import the `Ogun` class from the Ogun Library.
2. We initialize the `Ogun` class by creating an instance called `ogun`.
3. We define the user's data as a dictionary with relevant attributes: `account_balance`, `account_age`, `work_status`, and `Salary`.
4. We use the default risk calculation method by chaining method calls to the `ogun` instance. We specify weights for each data attribute using the `.score()` method.
5. Finally, we call the `.get()` method to perform the risk assessment and obtain the result, which includes the risk rating and status.
6. We print the risk assessment result, including the user's risk rating and status.
This is a basic example of how to use the Ogun Library for risk assessment. You can customize the library further by creating custom filters, custom risk calculation methods, and enhancing default methods to meet your specific needs.
## **3. Library Overview**
### **Library Structure**
Creating a comprehensive library structure requires organizing your code and files in a clear and maintainable manner. Here's a suggested directory structure for your Ogun Library:
```
ogun/
│
├── ogun/
│ ├── __init__.py
│ ├── filters/
│ │ ├── __init__.py
│ │ └── django_filter.py
│ ├── methods/
│ │ ├── __init__.py
│ │ ├── beta.py
│ │ ├── cvar.py
│ │ ├── default.py
│ │ ├── engine.py
│ │ ├── sharpe.py
│ │ ├── st_dev.py
│ │ └── var.py
│ └── ogun.py
│
├── docs/
│ └── user_guide.md
│
├── examples/
│ └── basic.py
│
├── tests/
│ ├── __init__.py
│ ├── test_custom_filters.py
│ ├── test_custom_methods.py
│ ├── test_default_methods.py
│ ├── test_enhance_methods.py
│ ├── test_ogun.py
│ └── test_utils.py
│
├── README.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── pyproject.toml
├── LICENSE
├── setup.py
├── requirements.txt
├── user_guide.md
└── .gitignore
```
Explanation of the directory structure:
- **ogun/**: The root directory of your Ogun Library.
- **ogun/**: This subdirectory contains the core code of your library.
- **__init__.py**: An initialization file for the `ogun` package.
- **filters/**: Subpackage for custom data filters.
- **__init__.py**: Initialization file for the filters package.
- **django_filter.py**: Contains the custom Django ORM filter function.
- **methods/**: Subpackage for risk calculation methods.
- **__init__.py**: Initialization file for the methods package.
- **beta.py**: Implementation of the Beta risk calculation method.
- **cvar.py**: Implementation of the Conditional Value at Risk (CVaR) method.
- **default.py**: Default risk calculation methods.
- **engine.py**: Base class for risk calculation engines.
- **sharpe.py**: Implementation of the Sharpe Ratio risk calculation method.
- **st_dev.py**: Implementation of the Standard Deviation risk calculation method.
- **var.py**: Implementation of the Value at Risk (VaR) risk calculation method.
- **ogun.py**: The main entry point of your library, where the `Ogun` class is defined.
- **docs/**: Directory for documentation files.
- **user_guide.md**: A comprehensive user guide explaining library usage and customization.
- **examples/**: Directory for example code.
- **basic.py**: Example code demonstrating basic library usage.
- **tests/**: Directory for unit tests.
- **__init__.py**: An initialization file for the tests package.
- **test_custom_filters.py**: Tests for custom data filters.
- **test_custom_methods.py**: Tests for custom risk calculation methods.
- **test_default_methods.py**: Tests for default risk calculation methods.
- **test_enhance_methods.py**: Tests for enhanced risk calculation methods.
- **test_ogun.py**: Tests for the core `Ogun` class.
- **test_utils.py**: Tests for utility functions.
- **README.md**: Documentation for your library, including project information and an overview.
- **CODE_OF_CONDUCT.md**: Code of conduct for contributors.
- **CONTRIBUTING.md**: Guidelines for contributing to the library.
- **pyproject.toml**: Configuration file for project dependencies and settings (e.g., for using `poetry`).
- **LICENSE**: The license for your library (e.g., MIT License).
- **setup.py**: A script for packaging and distributing your library.
- **requirements.txt**: List of dependencies required to run your library.
- **user_guide.md**: Comprehensive user guide with detailed explanations and examples.
- **.gitignore**: File specifying which files or directories should be ignored by version control (e.g., Git).
This directory structure organizes your library into distinct sections, making it easy for users and contributors to navigate and understand. It separates code, documentation, tests, and examples, promoting modularity and maintainability.
---
## **4. Basic Usage**
### **Initializing Ogun**
To use the library, create an instance of the `Ogun` class:
```python
from ogun import Ogun
ogun = Ogun()
```
### **Setting Data**
Set the data for risk assessment using a dictionary:
```python
data = {
"account_balance": 10,
"account_age": 5,
"work_status": 4,
"Salary": 10,
}
ogun.data(data)
```
### **Selecting a Risk Calculation Method**
Choose a risk calculation method. If no method is specified, the default method is used.
```python
# Use the default method
ogun.using()
```
### **Scoring Data**
Assign scores to data points using the `score` method:
```python
ogun.score("account_balance", 10)
ogun.score("account_age", 5)
ogun.score("work_status", 4)
ogun.score("Salary", 10)
```
### **Getting the Risk Rating**
Calculate risk and retrieve the risk rating and status:
```python
result = ogun.get()
print("Risk Rating:", result.rating)
print("Status:", result.status)
```
---
## **5. Extending the Library**
### **Adding Custom Risk Calculation Methods**
Custom risk calculation methods extend the capabilities of the Ogun Library by allowing you to define your own risk assessment algorithms. You can create custom methods to take into account domain-specific factors or unique data sources. Here's how to create custom risk calculation methods:
**Example: Custom Risk Calculation Method for Finance Industry**
```python
# Import necessary modules
from ogun import Engine
# Define a custom risk calculation class
class CustomFinanceRiskCalculator(Engine):
def calculate(self):
# Implement your custom risk calculation logic here
pass
```
In this example, we create a custom risk calculation method tailored to the finance industry. You can implement your own logic inside the `calculate` method to factor in additional financial metrics or industry-specific considerations.
To use the custom risk calculation method:
```python
# Use the custom risk calculation method with your Ogun instance
result = ogun.data(data).using(CustomFinanceRiskCalculator).get()
```
### **Creating Custom Filters**
Custom filters allow you to apply domain-specific rules and criteria to your data before calculating risk. They enable you to preprocess and manipulate the data to ensure that the risk assessment is tailored to your specific requirements. Here's how to create custom filters:
**Example: Custom Filter to Exclude Data Points Below a Threshold**
```python
# Define a custom filter function
def custom_filter(data, threshold):
filtered_data = {key: value for key, value in data.items() if value >= threshold}
return filtered_data
```
In this example, the `custom_filter` function filters out data points with values below a specified threshold. You can create similar custom filter functions to address specific data preprocessing needs in your risk assessment.
To use the custom filter:
```python
# Apply the custom filter to your data
filtered_data = custom_filter(data, threshold=5)
# Use the filtered data in your Ogun library instance
ogun.data(filtered_data)
```
### **Enhancing the Default Risk Calculation Method**
Enhancing default risk calculation methods allows you to modify or extend the built-in risk assessment algorithms to better suit your specific use cases. You might want to add additional data processing steps, custom scoring rules, or other modifications to improve the accuracy of your risk assessments. Here's how to enhance default risk calculation methods:
**Example: Enhancing the Default Risk Calculation Method**
```python
# Import necessary modules
from ogun import Engine, StandardDeviation
# Define a custom risk calculation class that extends the default method
class EnhancedRiskCalculator(StandardDeviation):
def calculate(self):
# Add custom processing or scoring logic here
# You can call the parent class's calculate method to retain default behavior
default_score = super().calculate()
# Implement custom modifications
custom_score = default_score + additional_score
return custom_score
```
In this example, we create an `EnhancedRiskCalculator` class that extends the default `StandardDeviation` risk calculation method. You can override the `calculate` method to add custom processing or scoring logic while still leveraging the default behavior when necessary.
To use the enhanced risk calculation method:
```python
# Use the enhanced risk calculation method with your Ogun instance
result = ogun.data(data).using(EnhancedRiskCalculator).get()
```
By enhancing default risk calculation methods, you can fine-tune the risk assessment process to better align with your specific business requirements or industry standards.
These examples demonstrate how to create custom filters, custom risk calculation methods, and enhance default risk calculation methods within the Ogun Library, allowing you to tailor risk assessments to your unique needs..
---
## **6. Advanced Usage**
### **Handling Exceptions**
Here's an example of how to use error handling when using your `Ogun` library:
```python
from ogun import Ogun
# Initialize Ogun
ogun = Ogun()
# Set data for risk assessment
data = {
"account_balance": 10,
"account_age": 5,
"work_status": 4,
"Salary": 10,
}
try:
# Use the default risk calculation method
result = (
ogun.data(data)
.using()
.score("account_balance", 10)
.score("account_age", 5)
.score("work_status", 4)
.score("Salary", 10)
.get()
)
# Print the risk assessment
print("Risk Rating:", result.rating)
print("Status:", result.status)
except RuntimeError as e:
# Handle the error gracefully
print(f"Error: {str(e)}")
```
In this code, we wrap the usage of the `Ogun` library in a `try` block, and if any exceptions occur during risk calculation, we catch them and print a custom error message. This ensures that your application can handle errors without crashing.
### **Customizing Risk Rating Thresholds**
To customize the risk rating thresholds, you can modify the `RiskResult` class file as follows:
```python
# In ogun.py
class RiskResult:
def __init__(self, total_score):
self.total_score = total_score
# Customize the risk rating thresholds
@property
def rating(self):
if self.total_score <= 10:
return "Very Low Risk"
elif self.total_score <= 20:
return "Low Risk"
elif self.total_score <= 40:
return "Moderate Risk"
elif self.total_score <= 60:
return "High Risk"
else:
return "Very High Risk"
@property
def status(self):
return "Approved" if self.rating in ["Very Low Risk", "Low Risk"] else "Denied"
```
In this modified [`RiskResult`](#example-1-using-a-custom-risk-calculation-method-) class, we have adjusted the thresholds for different risk ratings. For example, a total score of up to 10 is now classified as "Very Low Risk," and the thresholds for other risk ratings have also been adjusted accordingly.
---
## **7. Examples**
Provide practical examples demonstrating various library features.
### **Example 1: Using a Custom Risk Calculation Method**
Customizing the `RiskResult` class in your Ogun Library allows you to define your own criteria for risk rating and status based on the calculated risk score. To do this, you can subclass the `RiskResult` class and override its methods to implement your custom logic. Below, I'll provide an example of how you can customize the `RiskResult` class with code and an example scenario.
**Customizing the RiskResult Class**
First, let's create a custom `RiskResult` class with custom rating and status logic:
```python
from ogun import RiskResult
class CustomRiskResult(RiskResult):
def __init__(self, total_score):
super().__init__(total_score)
@property
def rating(self):
if self.total_score <= 20:
return "Very Low Risk"
elif self.total_score <= 40:
return "Low Risk"
elif self.total_score <= 60:
return "Moderate Risk"
elif self.total_score <= 80:
return "High Risk"
else:
return "Very High Risk"
@property
def status(self):
if self.rating in ["Very Low Risk", "Low Risk"]:
return "Approved"
else:
return "Denied"
```
In this example, we've created a custom `CustomRiskResult` class that inherits from the `RiskResult` class and overrides the `rating` and `status` properties. The custom rating logic categorizes risk into five categories, and the custom status logic approves applications with "Very Low Risk" or "Low Risk" ratings and denies others.
**Using the Custom RiskResult Class**
Now, let's use this custom `CustomRiskResult` class in your Ogun code:
```python
from ogun import Ogun
# Initialize Ogun
ogun = Ogun()
# Set data for risk assessment
data = {
"account_balance": 10,
"account_age": 5,
"work_status": 4,
"Salary": 10,
}
# Use the default risk calculation method
result = (
ogun.data(data)
.using()
.score("account_balance", 10)
.score("account_age", 5)
.score("work_status", 4)
.score("Salary", 10)
.get()
)
# Use the custom RiskResult class
custom_result = CustomRiskResult(result.total_score)
print("Custom Risk Rating:", custom_result.rating)
print("Custom Status:", custom_result.status)
```
In this code, we create an instance of the `CustomRiskResult` class based on the result obtained from the default risk calculation. This allows us to apply our custom risk rating and status logic to the same risk assessment.
This example demonstrates how you can customize the `RiskResult` class to implement your own risk rating and status criteria to fit specific business requirements or risk assessment scenarios.
### **Example 2: Customizing Thresholds**
Check out Customising RiskResult Class
---
## **8. FAQs**
**1. What is the purpose of the Ogun Library?**
- The Ogun Library is designed for risk assessment. It enables users to evaluate and quantify risk in various contexts, industries, and domains.
**2. What types of risk can the Ogun Library assess?**
- Ogun can assess a wide range of risks, including financial risk, credit risk, operational risk, and more. Its flexibility allows users to adapt it to specific risk scenarios.
**3. How does the library handle customization?**
- Ogun is highly customizable. Users can define their own risk factors, apply custom weights, and create custom risk assessment methods tailored to their needs.
**4. What default risk calculation methods are available?**
- Ogun provides default methods like Standard Deviation, Value at Risk (VaR), Conditional Value at Risk (CVaR), Sharpe Ratio, Beta, and more, which can be used as starting points for risk assessment.
**5. Can I extend the library's functionality?**
- Yes, the library is designed for extensibility. You can add custom filters, create custom risk calculation methods, and enhance default methods to meet specific use cases.
**6. Is the library suitable for large datasets?**
- Yes, Ogun can handle risk assessments for both individual data points and large datasets, making it scalable for various applications.
**7. What types of data sources does the library support?**
- Ogun is compatible with various data sources and structures, allowing users to adapt it to their specific data requirements.
**8. Is there documentation available for the library?**
- Yes, the library includes comprehensive documentation, including a user guide, to help users understand its capabilities and conduct risk assessments effectively.
**9. How can I ensure the reliability of risk assessment results?**
- Ogun incorporates a testing framework to ensure the accuracy and reliability of risk assessment methods.
**10. Is the Ogun Library open-source?**
- Yes, the library is open-source and can be used and extended by the community.
**11. How can I contribute to the Ogun Library?**
- You can contribute to the library by following the guidelines provided in the CONTRIBUTING.md file in the repository.
**12. Where can I get support or ask questions about the library?**
- For support, questions, or discussions, you can refer to the library's GitHub repository.
## **9. Support**
you can refer to the library's GitHub repository issues
## **10. Contributing**
We welcome contributions from the community! Please refer to the [Contributing Guidelines](CONTRIBUTING.md) for information on how to get started, code style, and the contribution process.
## **11. License**
This project is licensed under the [MIT License](LICENSE).
---
Raw data
{
"_id": null,
"home_page": "https://github.com/netesy/ogun",
"name": "ogun",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "risk,engine,analysis,collaborative filtering",
"author": "Emmanuel Olisah",
"author_email": "Emmanuel Olisah <manuelolisah@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/2e/32/3cb105313bad8376bd566729879225e1d422d68d8bc2693b363086a40a3c/ogun-0.0.1.tar.gz",
"platform": null,
"description": "\r\n\r\n# **Ogun Library**\r\n\r\n![Ogun Library Logo](ogun_logo.png)\r\n\r\nThe Ogun Library is a versatile risk assessment tool designed to quantify risk in various domains, industries, and contexts. Whether you need to assess financial risk, credit risk, or operational risk, Ogun offers customization, modularity, and default methods to meet your specific risk assessment needs\r\n\r\n## **Table of Contents**\r\n\r\n- [**Ogun Library**](#ogun-library)\r\n - [**Table of Contents**](#table-of-contents)\r\n - [**1. Introduction**](#1-introduction)\r\n - [**2. Getting Started**](#2-getting-started)\r\n - [**Installation**](#installation)\r\n - [**Quick Start**](#quick-start)\r\n - [**3. Library Overview**](#3-library-overview)\r\n - [**Library Structure**](#library-structure)\r\n - [**4. Basic Usage**](#4-basic-usage)\r\n - [**Initializing Ogun**](#initializing-ogun)\r\n - [**Setting Data**](#setting-data)\r\n - [**Selecting a Risk Calculation Method**](#selecting-a-risk-calculation-method)\r\n - [**Scoring Data**](#scoring-data)\r\n - [**Getting the Risk Rating**](#getting-the-risk-rating)\r\n - [**5. Extending the Library**](#5-extending-the-library)\r\n - [**Adding Custom Risk Calculation Methods**](#adding-custom-risk-calculation-methods)\r\n - [**Creating Custom Filters**](#creating-custom-filters)\r\n - [**Enhancing the Default Risk Calculation Method**](#enhancing-the-default-risk-calculation-method)\r\n - [**6. Advanced Usage**](#6-advanced-usage)\r\n - [**Handling Exceptions**](#handling-exceptions)\r\n - [**Customizing Risk Rating Thresholds**](#customizing-risk-rating-thresholds)\r\n - [**7. Examples**](#7-examples)\r\n - [**Example 1: Using a Custom Risk Calculation Method**](#example-1-using-a-custom-risk-calculation-method)\r\n - [**Example 2: Customizing Thresholds**](#example-2-customizing-thresholds)\r\n - [**8. FAQs**](#8-faqs)\r\n - [**9. Support**](#9-support)\r\n - [**10. Contributing**](#10-contributing)\r\n - [**11. License**](#11-license)\r\n\r\n\r\n\r\n## **1. Introduction**\r\n\r\nThe Ogun Library is a versatile risk assessment tool with customization, modularity, and default methods for quantifying risk in various domains.\r\n\r\n## **2. Getting Started**\r\n\r\n### **Installation**\r\n\r\nProvide instructions on how to install the library.\r\n\r\n```bash\r\npip install ogun\r\n```\r\n\r\n### **Quick Start**\r\n\r\nCertainly! Here's a quick example of how to use the Ogun Library for risk assessment:\r\n\r\nSuppose you have the following data for a user:\r\n\r\n- `account_balance`: 10\r\n- `account_age`: 5\r\n- `work_status`: 4\r\n- `Salary`: 10\r\n\r\nYou want to assess the user's risk using the default risk calculation method provided by the Ogun Library.\r\n\r\n```python\r\nfrom ogun import Ogun\r\n\r\n# Initialize Ogun\r\nogun = Ogun()\r\n\r\n# Set the user's data for risk assessment\r\ndata = {\r\n \"account_balance\": 10,\r\n \"account_age\": 5,\r\n \"work_status\": 4,\r\n \"Salary\": 10,\r\n}\r\n\r\n# Use the default risk calculation method\r\nresult = (\r\n ogun.data(data)\r\n .using()\r\n .score(\"account_balance\", 10)\r\n .score(\"account_age\", 5)\r\n .score(\"work_status\", 4)\r\n .score(\"Salary\", 10)\r\n .get()\r\n)\r\n\r\n# Print the risk assessment\r\nprint(\"Risk Rating:\", result.rating)\r\nprint(\"Status:\", result.status)\r\n```\r\n\r\nIn this example:\r\n\r\n1. We import the `Ogun` class from the Ogun Library.\r\n\r\n2. We initialize the `Ogun` class by creating an instance called `ogun`.\r\n\r\n3. We define the user's data as a dictionary with relevant attributes: `account_balance`, `account_age`, `work_status`, and `Salary`.\r\n\r\n4. We use the default risk calculation method by chaining method calls to the `ogun` instance. We specify weights for each data attribute using the `.score()` method.\r\n\r\n5. Finally, we call the `.get()` method to perform the risk assessment and obtain the result, which includes the risk rating and status.\r\n\r\n6. We print the risk assessment result, including the user's risk rating and status.\r\n\r\nThis is a basic example of how to use the Ogun Library for risk assessment. You can customize the library further by creating custom filters, custom risk calculation methods, and enhancing default methods to meet your specific needs.\r\n\r\n## **3. Library Overview**\r\n\r\n### **Library Structure**\r\n\r\nCreating a comprehensive library structure requires organizing your code and files in a clear and maintainable manner. Here's a suggested directory structure for your Ogun Library:\r\n\r\n```\r\nogun/\r\n\u2502\r\n\u251c\u2500\u2500 ogun/\r\n\u2502 \u251c\u2500\u2500 __init__.py\r\n\u2502 \u251c\u2500\u2500 filters/\r\n\u2502 \u2502 \u251c\u2500\u2500 __init__.py\r\n\u2502 \u2502 \u2514\u2500\u2500 django_filter.py\r\n\u2502 \u251c\u2500\u2500 methods/\r\n\u2502 \u2502 \u251c\u2500\u2500 __init__.py\r\n\u2502 \u2502 \u251c\u2500\u2500 beta.py\r\n\u2502 \u2502 \u251c\u2500\u2500 cvar.py\r\n\u2502 \u2502 \u251c\u2500\u2500 default.py\r\n\u2502 \u2502 \u251c\u2500\u2500 engine.py\r\n\u2502 \u2502 \u251c\u2500\u2500 sharpe.py\r\n\u2502 \u2502 \u251c\u2500\u2500 st_dev.py\r\n\u2502 \u2502 \u2514\u2500\u2500 var.py\r\n\u2502 \u2514\u2500\u2500 ogun.py\r\n\u2502\r\n\u251c\u2500\u2500 docs/\r\n\u2502 \u2514\u2500\u2500 user_guide.md\r\n\u2502\r\n\u251c\u2500\u2500 examples/\r\n\u2502 \u2514\u2500\u2500 basic.py\r\n\u2502\r\n\u251c\u2500\u2500 tests/\r\n\u2502 \u251c\u2500\u2500 __init__.py\r\n\u2502 \u251c\u2500\u2500 test_custom_filters.py\r\n\u2502 \u251c\u2500\u2500 test_custom_methods.py\r\n\u2502 \u251c\u2500\u2500 test_default_methods.py\r\n\u2502 \u251c\u2500\u2500 test_enhance_methods.py\r\n\u2502 \u251c\u2500\u2500 test_ogun.py\r\n\u2502 \u2514\u2500\u2500 test_utils.py\r\n\u2502\r\n\u251c\u2500\u2500 README.md\r\n\u251c\u2500\u2500 CODE_OF_CONDUCT.md\r\n\u251c\u2500\u2500 CONTRIBUTING.md\r\n\u251c\u2500\u2500 pyproject.toml\r\n\u251c\u2500\u2500 LICENSE\r\n\u251c\u2500\u2500 setup.py\r\n\u251c\u2500\u2500 requirements.txt\r\n\u251c\u2500\u2500 user_guide.md\r\n\u2514\u2500\u2500 .gitignore\r\n```\r\n\r\nExplanation of the directory structure:\r\n\r\n- **ogun/**: The root directory of your Ogun Library.\r\n\r\n - **ogun/**: This subdirectory contains the core code of your library.\r\n - **__init__.py**: An initialization file for the `ogun` package.\r\n - **filters/**: Subpackage for custom data filters.\r\n - **__init__.py**: Initialization file for the filters package.\r\n - **django_filter.py**: Contains the custom Django ORM filter function.\r\n - **methods/**: Subpackage for risk calculation methods.\r\n - **__init__.py**: Initialization file for the methods package.\r\n - **beta.py**: Implementation of the Beta risk calculation method.\r\n - **cvar.py**: Implementation of the Conditional Value at Risk (CVaR) method.\r\n - **default.py**: Default risk calculation methods.\r\n - **engine.py**: Base class for risk calculation engines.\r\n - **sharpe.py**: Implementation of the Sharpe Ratio risk calculation method.\r\n - **st_dev.py**: Implementation of the Standard Deviation risk calculation method.\r\n - **var.py**: Implementation of the Value at Risk (VaR) risk calculation method.\r\n - **ogun.py**: The main entry point of your library, where the `Ogun` class is defined.\r\n\r\n - **docs/**: Directory for documentation files.\r\n - **user_guide.md**: A comprehensive user guide explaining library usage and customization.\r\n\r\n - **examples/**: Directory for example code.\r\n - **basic.py**: Example code demonstrating basic library usage.\r\n\r\n - **tests/**: Directory for unit tests.\r\n - **__init__.py**: An initialization file for the tests package.\r\n - **test_custom_filters.py**: Tests for custom data filters.\r\n - **test_custom_methods.py**: Tests for custom risk calculation methods.\r\n - **test_default_methods.py**: Tests for default risk calculation methods.\r\n - **test_enhance_methods.py**: Tests for enhanced risk calculation methods.\r\n - **test_ogun.py**: Tests for the core `Ogun` class.\r\n - **test_utils.py**: Tests for utility functions.\r\n\r\n - **README.md**: Documentation for your library, including project information and an overview.\r\n - **CODE_OF_CONDUCT.md**: Code of conduct for contributors.\r\n - **CONTRIBUTING.md**: Guidelines for contributing to the library.\r\n - **pyproject.toml**: Configuration file for project dependencies and settings (e.g., for using `poetry`).\r\n - **LICENSE**: The license for your library (e.g., MIT License).\r\n - **setup.py**: A script for packaging and distributing your library.\r\n - **requirements.txt**: List of dependencies required to run your library.\r\n - **user_guide.md**: Comprehensive user guide with detailed explanations and examples.\r\n - **.gitignore**: File specifying which files or directories should be ignored by version control (e.g., Git).\r\n\r\nThis directory structure organizes your library into distinct sections, making it easy for users and contributors to navigate and understand. It separates code, documentation, tests, and examples, promoting modularity and maintainability.\r\n\r\n---\r\n\r\n## **4. Basic Usage**\r\n\r\n### **Initializing Ogun**\r\n\r\nTo use the library, create an instance of the `Ogun` class:\r\n\r\n```python\r\nfrom ogun import Ogun\r\n\r\nogun = Ogun()\r\n```\r\n\r\n### **Setting Data**\r\n\r\nSet the data for risk assessment using a dictionary:\r\n\r\n```python\r\ndata = {\r\n \"account_balance\": 10,\r\n \"account_age\": 5,\r\n \"work_status\": 4,\r\n \"Salary\": 10,\r\n}\r\n\r\nogun.data(data)\r\n```\r\n\r\n### **Selecting a Risk Calculation Method**\r\n\r\nChoose a risk calculation method. If no method is specified, the default method is used.\r\n\r\n```python\r\n# Use the default method\r\nogun.using()\r\n```\r\n\r\n### **Scoring Data**\r\n\r\nAssign scores to data points using the `score` method:\r\n\r\n```python\r\nogun.score(\"account_balance\", 10)\r\nogun.score(\"account_age\", 5)\r\nogun.score(\"work_status\", 4)\r\nogun.score(\"Salary\", 10)\r\n```\r\n\r\n### **Getting the Risk Rating**\r\n\r\nCalculate risk and retrieve the risk rating and status:\r\n\r\n```python\r\nresult = ogun.get()\r\n\r\nprint(\"Risk Rating:\", result.rating)\r\nprint(\"Status:\", result.status)\r\n```\r\n\r\n---\r\n\r\n## **5. Extending the Library**\r\n\r\n### **Adding Custom Risk Calculation Methods**\r\n\r\nCustom risk calculation methods extend the capabilities of the Ogun Library by allowing you to define your own risk assessment algorithms. You can create custom methods to take into account domain-specific factors or unique data sources. Here's how to create custom risk calculation methods:\r\n\r\n**Example: Custom Risk Calculation Method for Finance Industry**\r\n\r\n```python\r\n# Import necessary modules\r\nfrom ogun import Engine\r\n\r\n# Define a custom risk calculation class\r\nclass CustomFinanceRiskCalculator(Engine):\r\n def calculate(self):\r\n # Implement your custom risk calculation logic here\r\n pass\r\n```\r\n\r\nIn this example, we create a custom risk calculation method tailored to the finance industry. You can implement your own logic inside the `calculate` method to factor in additional financial metrics or industry-specific considerations.\r\n\r\nTo use the custom risk calculation method:\r\n\r\n```python\r\n# Use the custom risk calculation method with your Ogun instance\r\nresult = ogun.data(data).using(CustomFinanceRiskCalculator).get()\r\n```\r\n\r\n### **Creating Custom Filters**\r\n\r\nCustom filters allow you to apply domain-specific rules and criteria to your data before calculating risk. They enable you to preprocess and manipulate the data to ensure that the risk assessment is tailored to your specific requirements. Here's how to create custom filters:\r\n\r\n**Example: Custom Filter to Exclude Data Points Below a Threshold**\r\n\r\n```python\r\n# Define a custom filter function\r\ndef custom_filter(data, threshold):\r\n filtered_data = {key: value for key, value in data.items() if value >= threshold}\r\n return filtered_data\r\n```\r\n\r\nIn this example, the `custom_filter` function filters out data points with values below a specified threshold. You can create similar custom filter functions to address specific data preprocessing needs in your risk assessment.\r\n\r\nTo use the custom filter:\r\n\r\n```python\r\n# Apply the custom filter to your data\r\nfiltered_data = custom_filter(data, threshold=5)\r\n\r\n# Use the filtered data in your Ogun library instance\r\nogun.data(filtered_data)\r\n```\r\n\r\n### **Enhancing the Default Risk Calculation Method**\r\n\r\nEnhancing default risk calculation methods allows you to modify or extend the built-in risk assessment algorithms to better suit your specific use cases. You might want to add additional data processing steps, custom scoring rules, or other modifications to improve the accuracy of your risk assessments. Here's how to enhance default risk calculation methods:\r\n\r\n**Example: Enhancing the Default Risk Calculation Method**\r\n\r\n```python\r\n# Import necessary modules\r\nfrom ogun import Engine, StandardDeviation\r\n\r\n# Define a custom risk calculation class that extends the default method\r\nclass EnhancedRiskCalculator(StandardDeviation):\r\n def calculate(self):\r\n # Add custom processing or scoring logic here\r\n # You can call the parent class's calculate method to retain default behavior\r\n default_score = super().calculate()\r\n\r\n # Implement custom modifications\r\n custom_score = default_score + additional_score\r\n\r\n return custom_score\r\n```\r\n\r\nIn this example, we create an `EnhancedRiskCalculator` class that extends the default `StandardDeviation` risk calculation method. You can override the `calculate` method to add custom processing or scoring logic while still leveraging the default behavior when necessary.\r\n\r\nTo use the enhanced risk calculation method:\r\n\r\n```python\r\n# Use the enhanced risk calculation method with your Ogun instance\r\nresult = ogun.data(data).using(EnhancedRiskCalculator).get()\r\n```\r\n\r\nBy enhancing default risk calculation methods, you can fine-tune the risk assessment process to better align with your specific business requirements or industry standards.\r\n\r\nThese examples demonstrate how to create custom filters, custom risk calculation methods, and enhance default risk calculation methods within the Ogun Library, allowing you to tailor risk assessments to your unique needs..\r\n\r\n---\r\n\r\n## **6. Advanced Usage**\r\n\r\n### **Handling Exceptions**\r\nHere's an example of how to use error handling when using your `Ogun` library:\r\n\r\n```python\r\nfrom ogun import Ogun\r\n\r\n# Initialize Ogun\r\nogun = Ogun()\r\n\r\n# Set data for risk assessment\r\ndata = {\r\n \"account_balance\": 10,\r\n \"account_age\": 5,\r\n \"work_status\": 4,\r\n \"Salary\": 10,\r\n}\r\n\r\ntry:\r\n # Use the default risk calculation method\r\n result = (\r\n ogun.data(data)\r\n .using()\r\n .score(\"account_balance\", 10)\r\n .score(\"account_age\", 5)\r\n .score(\"work_status\", 4)\r\n .score(\"Salary\", 10)\r\n .get()\r\n )\r\n\r\n # Print the risk assessment\r\n print(\"Risk Rating:\", result.rating)\r\n print(\"Status:\", result.status)\r\nexcept RuntimeError as e:\r\n # Handle the error gracefully\r\n print(f\"Error: {str(e)}\")\r\n```\r\n\r\nIn this code, we wrap the usage of the `Ogun` library in a `try` block, and if any exceptions occur during risk calculation, we catch them and print a custom error message. This ensures that your application can handle errors without crashing.\r\n\r\n### **Customizing Risk Rating Thresholds**\r\n\r\nTo customize the risk rating thresholds, you can modify the `RiskResult` class file as follows:\r\n\r\n```python\r\n# In ogun.py\r\n\r\nclass RiskResult:\r\n def __init__(self, total_score):\r\n self.total_score = total_score\r\n\r\n # Customize the risk rating thresholds\r\n @property\r\n def rating(self):\r\n if self.total_score <= 10:\r\n return \"Very Low Risk\"\r\n elif self.total_score <= 20:\r\n return \"Low Risk\"\r\n elif self.total_score <= 40:\r\n return \"Moderate Risk\"\r\n elif self.total_score <= 60:\r\n return \"High Risk\"\r\n else:\r\n return \"Very High Risk\"\r\n\r\n @property\r\n def status(self):\r\n return \"Approved\" if self.rating in [\"Very Low Risk\", \"Low Risk\"] else \"Denied\"\r\n```\r\n\r\nIn this modified [`RiskResult`](#example-1-using-a-custom-risk-calculation-method-) class, we have adjusted the thresholds for different risk ratings. For example, a total score of up to 10 is now classified as \"Very Low Risk,\" and the thresholds for other risk ratings have also been adjusted accordingly.\r\n\r\n---\r\n\r\n## **7. Examples**\r\n\r\nProvide practical examples demonstrating various library features.\r\n\r\n### **Example 1: Using a Custom Risk Calculation Method** \r\n\r\nCustomizing the `RiskResult` class in your Ogun Library allows you to define your own criteria for risk rating and status based on the calculated risk score. To do this, you can subclass the `RiskResult` class and override its methods to implement your custom logic. Below, I'll provide an example of how you can customize the `RiskResult` class with code and an example scenario.\r\n\r\n**Customizing the RiskResult Class**\r\n\r\nFirst, let's create a custom `RiskResult` class with custom rating and status logic:\r\n\r\n```python\r\nfrom ogun import RiskResult\r\n\r\nclass CustomRiskResult(RiskResult):\r\n def __init__(self, total_score):\r\n super().__init__(total_score)\r\n\r\n @property\r\n def rating(self):\r\n if self.total_score <= 20:\r\n return \"Very Low Risk\"\r\n elif self.total_score <= 40:\r\n return \"Low Risk\"\r\n elif self.total_score <= 60:\r\n return \"Moderate Risk\"\r\n elif self.total_score <= 80:\r\n return \"High Risk\"\r\n else:\r\n return \"Very High Risk\"\r\n\r\n @property\r\n def status(self):\r\n if self.rating in [\"Very Low Risk\", \"Low Risk\"]:\r\n return \"Approved\"\r\n else:\r\n return \"Denied\"\r\n```\r\n\r\nIn this example, we've created a custom `CustomRiskResult` class that inherits from the `RiskResult` class and overrides the `rating` and `status` properties. The custom rating logic categorizes risk into five categories, and the custom status logic approves applications with \"Very Low Risk\" or \"Low Risk\" ratings and denies others.\r\n\r\n**Using the Custom RiskResult Class**\r\n\r\nNow, let's use this custom `CustomRiskResult` class in your Ogun code:\r\n\r\n```python\r\nfrom ogun import Ogun\r\n\r\n# Initialize Ogun\r\nogun = Ogun()\r\n\r\n# Set data for risk assessment\r\ndata = {\r\n \"account_balance\": 10,\r\n \"account_age\": 5,\r\n \"work_status\": 4,\r\n \"Salary\": 10,\r\n}\r\n\r\n# Use the default risk calculation method\r\nresult = (\r\n ogun.data(data)\r\n .using()\r\n .score(\"account_balance\", 10)\r\n .score(\"account_age\", 5)\r\n .score(\"work_status\", 4)\r\n .score(\"Salary\", 10)\r\n .get()\r\n)\r\n\r\n# Use the custom RiskResult class\r\ncustom_result = CustomRiskResult(result.total_score)\r\n\r\nprint(\"Custom Risk Rating:\", custom_result.rating)\r\nprint(\"Custom Status:\", custom_result.status)\r\n```\r\n\r\nIn this code, we create an instance of the `CustomRiskResult` class based on the result obtained from the default risk calculation. This allows us to apply our custom risk rating and status logic to the same risk assessment.\r\n\r\nThis example demonstrates how you can customize the `RiskResult` class to implement your own risk rating and status criteria to fit specific business requirements or risk assessment scenarios.\r\n\r\n### **Example 2: Customizing Thresholds**\r\n\r\nCheck out Customising RiskResult Class\r\n\r\n---\r\n\r\n## **8. FAQs**\r\n\r\n**1. What is the purpose of the Ogun Library?**\r\n - The Ogun Library is designed for risk assessment. It enables users to evaluate and quantify risk in various contexts, industries, and domains.\r\n\r\n**2. What types of risk can the Ogun Library assess?**\r\n - Ogun can assess a wide range of risks, including financial risk, credit risk, operational risk, and more. Its flexibility allows users to adapt it to specific risk scenarios.\r\n\r\n**3. How does the library handle customization?**\r\n - Ogun is highly customizable. Users can define their own risk factors, apply custom weights, and create custom risk assessment methods tailored to their needs.\r\n\r\n**4. What default risk calculation methods are available?**\r\n - Ogun provides default methods like Standard Deviation, Value at Risk (VaR), Conditional Value at Risk (CVaR), Sharpe Ratio, Beta, and more, which can be used as starting points for risk assessment.\r\n\r\n**5. Can I extend the library's functionality?**\r\n - Yes, the library is designed for extensibility. You can add custom filters, create custom risk calculation methods, and enhance default methods to meet specific use cases.\r\n\r\n**6. Is the library suitable for large datasets?**\r\n - Yes, Ogun can handle risk assessments for both individual data points and large datasets, making it scalable for various applications.\r\n\r\n**7. What types of data sources does the library support?**\r\n - Ogun is compatible with various data sources and structures, allowing users to adapt it to their specific data requirements.\r\n\r\n**8. Is there documentation available for the library?**\r\n - Yes, the library includes comprehensive documentation, including a user guide, to help users understand its capabilities and conduct risk assessments effectively.\r\n\r\n**9. How can I ensure the reliability of risk assessment results?**\r\n - Ogun incorporates a testing framework to ensure the accuracy and reliability of risk assessment methods.\r\n\r\n**10. Is the Ogun Library open-source?**\r\n - Yes, the library is open-source and can be used and extended by the community.\r\n\r\n**11. How can I contribute to the Ogun Library?**\r\n - You can contribute to the library by following the guidelines provided in the CONTRIBUTING.md file in the repository.\r\n\r\n**12. Where can I get support or ask questions about the library?**\r\n - For support, questions, or discussions, you can refer to the library's GitHub repository.\r\n\r\n\r\n## **9. Support**\r\n\r\nyou can refer to the library's GitHub repository issues\r\n\r\n## **10. Contributing**\r\n\r\nWe welcome contributions from the community! Please refer to the [Contributing Guidelines](CONTRIBUTING.md) for information on how to get started, code style, and the contribution process.\r\n\r\n## **11. License**\r\n\r\nThis project is licensed under the [MIT License](LICENSE).\r\n\r\n---\r\n",
"bugtrack_url": null,
"license": "",
"summary": "An open-source risk analysis library in Python",
"version": "0.0.1",
"project_urls": {
"Bug Tracker": "https://github.com/netesy/ogun/issues",
"Documentation": "https://github.com/netesy/ogun/tree/main/docs",
"Homepage": "https://github.com/netesy/ogun",
"Source Code": "https://github.com/netesy/ogun"
},
"split_keywords": [
"risk",
"engine",
"analysis",
"collaborative filtering"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ea4fa74c6d201ebe19aacba26d7b3b50640c2f75ffbd995969a1c15621b50156",
"md5": "299c026df0a60bad9471b5efb7b7891e",
"sha256": "74398966a440c12e0751e0e6c7fd3e9977f5de0677847b18ac8c90c6d3c50e06"
},
"downloads": -1,
"filename": "ogun-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "299c026df0a60bad9471b5efb7b7891e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 7912,
"upload_time": "2023-09-10T00:49:53",
"upload_time_iso_8601": "2023-09-10T00:49:53.646475Z",
"url": "https://files.pythonhosted.org/packages/ea/4f/a74c6d201ebe19aacba26d7b3b50640c2f75ffbd995969a1c15621b50156/ogun-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2e323cb105313bad8376bd566729879225e1d422d68d8bc2693b363086a40a3c",
"md5": "02d3cc3237604a6bdae31af63083bc34",
"sha256": "3e726ba8a85c2378cf5aa1aaf3677056be22b0043611946545c5a5480a84d36e"
},
"downloads": -1,
"filename": "ogun-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "02d3cc3237604a6bdae31af63083bc34",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 9014,
"upload_time": "2023-09-10T00:49:56",
"upload_time_iso_8601": "2023-09-10T00:49:56.161373Z",
"url": "https://files.pythonhosted.org/packages/2e/32/3cb105313bad8376bd566729879225e1d422d68d8bc2693b363086a40a3c/ogun-0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-10 00:49:56",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "netesy",
"github_project": "ogun",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "ogun"
}