Skip to content

PEP8 style algorithm API - #7909

Merged
Martin-Molinero merged 16 commits into
QuantConnect:masterfrom
jhonabreul:feature-python-pep-style
Apr 12, 2024
Merged

PEP8 style algorithm API #7909
Martin-Molinero merged 16 commits into
QuantConnect:masterfrom
jhonabreul:feature-python-pep-style

Conversation

@jhonabreul

@jhonabreul jhonabreul commented Apr 10, 2024

Copy link
Copy Markdown
Collaborator

Description

Add PEP8 style API for Python algorithms:

  • Python algorithms can now be written following PEP8 guidelines
  • QCAlgorithm methods can be overriden with PEP8 names (snake case) as shown in the added Python algorithms: Initialize can be overriden with initialize, OnOrderEvent can be overriden with on_order_event, etc.
  • All of the existing properties, fields and methods can be accessed with their PEP8 corresponding names, so self.Portfolio[self.Securities[self.spy]].HoldingsValue can be replaced with self.portfolio[self.securities[self.spy]].holdings_value.
  • If a snake-case version of a method is used with named arguments, those also must be snake-cased. For instance, self.add_equity("SPY", extended_market_hours=True).
  • Enum values also follow PEP8 guidelines, so they can be used as Resolution.MINUTE or OrderStatus.PARTIALLY_FILLED.

Depends on QuantConnect/pythonnet#83 and QuantConnect/pythonnet#84

Related Issue

Motivation and Context

Having PEP8 conforming algorithms.
Users comming from Python would find the API easier to use.

Requires Documentation Change

Document the new API.

How Has This Been Tested?

  • Unit tests
  • Regression algorithms

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which improves implementation)
  • Performance (non-breaking change which improves performance. Please add associated performance test and results)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Non-functional change (xml comments/documentation/etc)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My branch follows the naming convention bug-<issue#>-<description> or feature-<issue#>-<description>

/// containing the new key-value pair along with the original ones.
/// We do this in order to avoid the overhead of using locks or concurrent dictionaries and still be thread-safe.
/// </summary>
private static Dictionary<string, T> AddToDictionary<T>(Dictionary<string, T> dictionary, string key, T value)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet! 👍

@jhonabreul
jhonabreul force-pushed the feature-python-pep-style branch from 7eb082c to cd17661 Compare April 11, 2024 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants