> For the complete documentation index, see [llms.txt](https://lijeffrey39.gitbook.io/sentiment-ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lijeffrey39.gitbook.io/sentiment-ai/data-collection/stock-setup.md).

# Generate Stock Features

First save stock tweets locally before generating stock features:

{% content-ref url="/pages/-MD0lAXaxQKGcCHvmviC" %}
[Stock tweets](/sentiment-ai/project-setup/tweet-setup.md)
{% endcontent-ref %}

Stock features are generated based on tweets made about a stock within a range of dates. For each stock, user tweets are first filtered to only include tweets made by 'expert' users determined by pre-generated [user features](/sentiment-ai/data-collection/user-setup/user-feature.md). The general purpose of these stock features is to associate a user's tweeted prediction with their corresponding user feature. [Example](/sentiment-ai/data-collection/stock-setup/stock-feature.md) stock feature

```python
for symbol in stocks:
    for date in date_range:
        tweets = findTweets(symbol, date)
        for tweet in tweets:
            username = tweet['username']
            date = tweet['time']
            user_feature = findUserFeature(symbol, date, date)
```

The tweets for each stock and date are first fetched and scanned. For each tweet, the user's features are found and saved with the tweet.

### Notes about these features

* Features are generated by only looking at the latest prediction by a user on a given day.
* A user's associated feature is found by looking at the most recent updated feature before the current prediction date&#x20;
